Professional Documents
Culture Documents
DBMS Exp3
DBMS Exp3
Experiment No-3
Aim: Create and populate database using Data Definition Language (DDL) and DML
Commands
Theory:
Structured Query Language (SQL) as we all know is the database language using which we can
perform certain operations on the existing database and, we can use this language to create a database.
SQL uses certain commands like Create, Drop, Insert, etc. to carry out the required tasks.
These SQL commands are categorized into four categories out of which two are detailed in this
experiment:
• CREATE: This command is used to create the database or its objects (like table, index,
function, views, store procedure, and triggers).
• DROP: This command is used to delete objects from the database.
• ALTER: This is used to alter the structure of the database.
• TRUNCATE: This is used to remove all records from a table, including all spaces allocated
for the records are removed.
• COMMENT: This is used to add comments to the data dictionary.
• RENAME: This is used to rename an object existing in the database.
• DESCRIBE: This is used to describe information about table structure.
1
Department of Computer Engineering
Academic Year 2021-2022
1) Create Command
Creating Database
Creating table:
The create table command defines each column of the table uniquely. Each column has minimum of
three attributes:
- Name
- Datatype
- Size (column width)
Each table column definition is a single clause in the create table syntax. Each table column
definition is separated from the other by a comma. Finally, the SQL statement is terminated
with a semicolon.
SYNTAX:
...
constraints
);
2
Department of Computer Engineering
Academic Year 2021-2022
Creating tables
-> );
-> );
3
Department of Computer Engineering
Academic Year 2021-2022
-> );
-> (
-> );
4
Department of Computer Engineering
Academic Year 2021-2022
5
Department of Computer Engineering
Academic Year 2021-2022
2) ALTER
Syntax:
E.g.
Syntax:
E.g.
6
Department of Computer Engineering
Academic Year 2021-2022
Syntax:
E.g.
7
Department of Computer Engineering
Academic Year 2021-2022
3) RENAME
Syntax:
E.g.
mysql> rename table departments to college_departments;
4) DROP:
Syntax:
E.g.
8
Department of Computer Engineering
Academic Year 2021-2022
5) TRUNCATE:
Syntax:
E.g.
college_departments;
9
Department of Computer Engineering
Academic Year 2021-2022
6) SHOW:
Syntax:
SHOW [DATABASES|TABLES];
E.g.
mysql> show
databases;
7) DESC:
Syntax: DESC
tablename
E.g.
10
Department of Computer Engineering
Academic Year 2021-2022
1) INSERT:
Syntax:
E.g.:
2)
SELECT:
Syntax:
E.g.
3) UPDATE:
11
Department of Computer Engineering
Academic Year 2021-2022
Syntax:
col1=val1, col2=val2,…
WHERE condition;
E.g.
-> marks = 80
4) DELETE:
This command removes one or more records from a table according to specified conditions.
Syntax:
WHERE condition;
E.g.
12
Department of Computer Engineering
Academic Year 2021-2022
Conclusion: Hence, we created the tables previously defined using DDL commands. We also
performed basic manipulation of data using DML commands.
13