Professional Documents
Culture Documents
&
CS2082 Database Management Systems
Laboratory
(LAB3)
Prof. Sambit Bakshi
Computer Science and Engineering,
National Institute of Technology, Rourkela.
bakshisambit@nitrkl.ac.in
DATA DEFINATION LANGUAGE
• DATA DEFINATION LANGUAGE (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.
Syntax :
Example:
Example:
Syntax :
ALTER TABLE table_name ALTER TABLE Student
DROP COLUMN column_name; DROP COLUMN COURSE;
ALTER TABLE – MODIFY
Syntax : Example:
Syntax: Example:
DROP object object_name
DROP TABLE STUDENT;
DROP TABLE table_name;
DROP DATABASE database_name;
TRUNCATE
• TRUNCATE statement is used to mark the extents of a table for deallocation (empty
for reuse).
Example:
Syntax:
TRUNCATE TABLE table_name; TRUNCATE TABLE Student_details;
DROP TRUNCATE DELETE
Syntax:
EXEC sp_rename ‘OldTableName', ‘NewTableName';
RENAME COLUMN
Syntax:
EXEC sp_rename ‘TableName.OldColumnName', ‘NewColumnName', 'COLUMN';
Example:
1. Single-line comments
2. Multi-line comments
3. Inline comments
Single line comments
Syntax: Example:
-- single line comment SELECT * FROM STUDENTS --WHERE Name = 'Raj';
Multi-line comments
Example:
Syntax:
/* multi-line comment*/ /* SELECT * FROM Students;
SELECT * FROM STUDENT_DETAILS;
SELECT * FROM Orders; */
SELECT * FROM Articles;
Inline comments
Example:
Syntax:
SELECT * FROM /* Customers; */ SELECT * FROM Students;
SELECT * FROM /*
STUDENT_DETAILS;
SELECT * FROM Orders;
SELECT * FROM */ Articles;
DATA MANIPULATION LANGUAGE
• DATA MANIPULATION LANGUAGE (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.
• Some commands that come under DML: INSERT, UPDATE, DELETE, MERGE,
CALL , EXPLAIN PLAN and LOCK TABLE.
INSERT
• The INSERT INTO statement of SQL is used to insert a new row in a table.
Syntax: Example:
Syntax: Example:
Syntax: Example:
• DCL includes commands such as GRANT and REVOKE which mainly deal with
the rights, permissions, and other controls of the database system.
Syntax: Example:
• REVOKE statement is used to revoke some or all of the privileges which have been
granted to a user in the past.
Syntax: Example:
Syntax: Example:
FLOAT(N) Floating precision number data from -1.79E + 308 to 1.79E + 308. 4 or 8 Byte
float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value
of n is 53.
REAL Floating precision number data from -3.40E + 38 to 3.40E + 38 4 Byte
STRING DATA TYPE
DATA TYPE DISCRIPTION MAX SIZE
Syntax: Example:
SELECT
DATEDIFF(interval, date1, date2) DATEDIFF(year, '2017/08/25',
'2011/08/25')
Interval : year, month, day, quarter
GETDATE
Syntax: Example:
SELECT GETDATE();
GETDATE()
Syntax: Example:
UPDATE Table_name
SET year_difference =
DATEDIFF(YEAR, date_of_birth , GETDATE())
WHERE date_of_birth IN (SELECT date_of_birth FROM Table_name)