Lab Session 1
Lab Session 1
SQL stands for Structured Query Language. It is used for storing and managing data in relational database
management system (RDMS). It is a standard language for Relational Database System. It enables a user to
create, read, update and delete relational databases and tables. _
All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their standard
database language. SQL allows users to query the database in a number of ways, using English-like
statements.
SQL (Structured Query Language) is used to perform operations on the records stored in the database, such
as updating records, inserting records, deleting records, creating and modifying database tables, views, etc.
SQL is not a database system , but it is a query language. SQL uses certain command like create, drop,
insert, etc. to carry out required tasks.
These SQL command are mainly categorized into four categories as:
DDL changes the structure of the table like creating a table, deleting a table, altering a table, etc.
All the command of DDL are auto-committed that means it permanently save all the changes in the database.
Here are some command that comes under DDL.
c. ALTER: It is used to alter the structure of the database. This change could be either to modify the
characteristics of an existing attribute or probably to add a new attribute
Syntax : ALTER TABLE table_name ADD column_name datatype[(size)].
ALTER TABLE table_name MODIFY column_name datatype[(size)]..
d. TRUNCATE: It is used to delete all the rows from the table and free the space containing the table.
..=Syntax : TRUNCATE TABLE table_name;
DML commands are used to modify the database. It is responsible for all form of changes in the
database.The command of DML is not auto-committed that means it can't permanently save all the changes
in the database. They can be rollback. Here are some command that comes under DDL.
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax : INSERT INTO TABLE_NAME
(col1, col2, col3,.... col N)
VALUES (value1, value2, value3, .... valueN);
b. UPDATE: This command is used to update or modify the value of a column in the table.
C= Syntax : UPDATE table_name SET [column_name1= value1,...column_nameN = valueN]
DCL includes commands such as GRANT and REVOKE which mainly deals with the right , permission and
other control of Database system. Here are some command that comes under DDL.
a. Grant: It is used to give user access privileges to a database.
TCL commands can only use with DML commands like INSERT, DELETE, and UPDATE only.Here are
some command that comes under DDL.
a. COMMIT: Commit command is used to save all the transactions to the database.
Syntax: COMMIT;
b. ROLLBACK: Rollback command is used to undo transactions that have not already been saved to the
database.
Syntax: ROLLBACK;
c. SAVEPOINT: It is used to roll the transaction back to certain point without rolling back the entire
transaction.
Syntax: SAVEPOINT SAVEPOINT_NAME;
DQL is used to fetch data from the database. It uses only one command – SELECT.
a. SELECT: This is the same as the projection operation of relational algebra. It is used to select the
attribute based on the condition described by WHERE clause.
Syntax : SELECT expressions
FROM TABLES
WHERE conditions;