DBMS File Practical Shail
DBMS File Practical Shail
Session: 2019-2020
● In case you want to install MySQL offline, you can download the mysql-installer-
community-<version>.exe file.
To install MySQL using the MySQL installer, double-click on the MySQL installer file
and follow the steps below:
Step 3 – Download the latest MySQL products: MySQL installer checks and
downloads the latest MySQL products including MySQL server, MySQL Workbench,
etc.
Step 4: Click the Next button to continue.
Step 5 – Choosing a Setup Type: there are several setup types available. Choose the
Full option to install all MySQL products and features.
Step 6 : Checking Requirements.
Step 7 – Installation Progress: MySQL Installer downloads all selected products. It will
take a while, depending on which products you selected and the speed of your internet
connection.
Step 7.1 – Installation Progress: Complete Downloading. Click the Next button to continue…
Step 9.1: MySQL Server Configuration: choose Windows service details including
Windows Service Name and account type, then click Next button to continue.
Step 10: Configuration Overview: MySQL Installer installs sample databases and
sample models.
Installation Completed: The installation completes. Click the Finish button to close the
installation wizard and launch the MySQL Workbench.
PROGRAM:
-2
AIM:- WAP to create a table having different fields
and datatypes.
CREATE DATABASE
A Database is defined as a structured set of data. So, in SQL the very first step to store
the data in a well-structured manner is to create a database. The CREATE
DATABASE statement is used to create a new database in SQL.
Syntax:
Example Query:
This query will create a new database in SQL and name the database as sin;
CREATE TABLE
We have learned above about creating databases. Now to store the data we need a table
to do that. The CREATE TABLE statement is used to create a table in SQL. We know
that a table comprises of rows and columns. So while creating tables we have to provide
all the information to SQL about the names of the columns, type of data to be stored in
columns, size of the data etc. Let us now dive into details on how to use CREATE
TABLE statement to create tables in SQL.
Syntax:
CREATE TABLE
table_name
( column1
data_type(size),
column2
data_type(size),
column3
data_type(size),
....
);
table_name: name of the table.
column1 name of the first column.
data_type: Type of data we want to store in the particular column. For example, int for
integer data.
size: Size of the data we can store in a particular column. For example if for a column
we specify the data_type as int
and size as 10 then this column can store an integer number of maximum 10 digits.
Example Query:
PROGRAM:
3
AIM:-WAP to create a table with different types of constraints.
CONSTRAINTS:-
Constraints can be specified when the table is created with the CREATE TABLE
statement, or after the table is created with the ALTER TABLE statement.
Syntax
CREATETABLEtable_
name ( column1
datatypeconstraint,
column2
datatypeconstraint,
column3
datatypeconstraint,
....
);
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This
ensures the accuracy and reliability of the data in the table. If there is any
violation between the constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints
apply to a column, and table level constraints apply to the whole table.
The NOT NULL constraint enforces a column to NOT accept NULL values.
This enforces a field to always contain a value, which means that you cannot insert
a new record, or update a record without adding a value to this field.
SQL NOT NULL on CREATE TABLE
The following SQL ensures that the "ID", "LastName", and "FirstName" columns will
NOT accept NULL values when the "Persons" table is created:
Example
To create a NOT NULL constraint on the "Age" column when the "Persons" table is
already created, use the following SQL:
The UNIQUE constraint ensures that all values in a column are different.
Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for
uniqueness for a column or set of columns.
However, you can have many UNIQUE constraints per table, but only one PRIMARY
KEY constraint per table.
SQL PRIMARY KEY Constraint
The following SQL creates a FOREIGN KEY on the "ID" column when the "Orders" table is
created:
Syntax
INSERT INTO TableName (Column1, Column2, Column3,
...,ColumnN) VALUES (value1, value2, value3, ...);
--If you don't want to mention the column names then use the below
UPDATE
This statement is used to modify the records already present in the table.
Syntax
UPDATE TableName
SET Column1 = Value1, Column2 =
Value2, ... WHERE Condition;
DELETE
Example Query:
PROGRAM:
5
AIM:- WAP to modify the table using Alter command.
ALTER:-
This command is used to delete, modify or add constraints or columns in an existing table.
You can use the ALTER TABLE statement with ADD/DROP Column command
according to your need. If you wish to add a column, then you will use the ADD
command, and if you wish to delete a column, then you will use the DROP COLUMN
command.
Syntax
ALTER TABLE
TableName ADD
ColumnName Datatype;
ALTER TABLE
TableName DROP
COLUMN ColumnName;
Example Query:
Example Query:
P
ROGRAM: 6
AIM:- WAP to explore Select statement using various
clauses like where ,order by, group by, having and aggregate
functions.
The SELECT statement is used to select a specific set of data from the database. The
data returned by the SELECT statement is stored in a result table called as result set.
As we all know that the ORDER BY statementis used to sort the results either in
ascending or descending order. We can use the ORDER BY statement with the
SELECT statement to retrieve specific data in ascending or descending order.
Syntax
SELECTColumnName1, ColumnName2,
ColumnName(N) FROMTableName
ORDERBYColumnName1, ColumnName2, ... ASC|DESC;
Use SELECT with GROUP BY
The GROUP BY statement is used with the SELECT statement to group the result-set
by one or more columns.
Syntax:
SELECTColumnName1, ColumnName2,...,
ColumnName(N) FROMTableName
WHERECondition
GROUPBYColumnNam
e(N)
ORDERBYColumnNam
e(N);
The HAVING clause can be used with the SELECT statement to retrieve data based on some
conditions.
Syntax:
SELECTColumnName1, ColumnName2, ColumnName(N)
FROMTableName
WHERECondition
GROUPBYColumnNam
e(N)
HAVINGCondition
ORDERBYColumnNam
e(N);