32
About Me Md. Selim Hossain Lecturer Dept. of CSE UTTARA UNIVERSITY House#05, Section#06, Road#15, Uttara, Dhaka-1230. Md. Selim Hossain 1

Data Definition and Data Manipulation Language-DDL & DML

Embed Size (px)

Citation preview

Page 1: Data Definition and Data Manipulation Language-DDL & DML

1

About Me

Md. Selim HossainLecturer

Dept. of CSEUTTARA UNIVERSITY

House#05, Section#06,Road#15, Uttara, Dhaka-1230.

Md. Selim Hossain

Page 2: Data Definition and Data Manipulation Language-DDL & DML

2

Database Management System (DBMS)Md. Selim Hossain

Page 3: Data Definition and Data Manipulation Language-DDL & DML

3

Topics for Today

Md. Selim Hossain

Page 4: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 4

Data Definition Language (DDL)

Data Manipulation Language (DML)

Page 5: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 5

SQL statements are divided into two major

categories:

Data Definition Language (DDL) and Data Manipulation Language (DML).

Page 6: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 6

Data Definition Language (DDL)

• DDL statements are used to build and modify the structure of tables and other objects in the database.

• DDL is a sub-language of SQL used to create and manipulate objects in a database. DDL provides the following statements to manipulate the object in database:

CREATE, ALTER, DROP, TRUNCATE, RENAME

Page 7: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 7

Data Definition Language (DDL) CREATE statement (to create objects in the database):• The CREATE statement in SQL creates a

component in a relational database management system (RDBMS).

• The CREATE command is used to establish a new database, table, index, or stored procedure.

Page 8: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 8

CREATE TABLE statement• A commonly used CREATE command is the

CREATE TABLE command. The typical usage is: CREATE TABLE [table name] ( [column

definitions] ) [table parameters]

Page 9: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 9

CREATE TABLE statement• An example of statement to create a table

named employees with a few columns is:

Page 10: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 10

CREATE TABLE statement

Note: The full structure of table can be viewed with the DESC command.

DESC <TABLE_NAME>

Page 11: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 11

DROP statement

• The DROP statement destroys an existing database, table, index, or view.

• A DROP statement in SQL removes a component from a relational database management system (RDBMS).

• Drop statement is used to delete an existing object from the database. It can also be used to delete any column from a table.

Page 12: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 12

DROP statement

• The DROP statement is distinct from the DELETE and TRUNCATE statements, in that DELETE and TRUNCATE do not remove the table itself. For example, a DELETE statement might delete some (or all) data from a table while leaving the table itself in the database, whereas a DROP statement removes the entire table from the database.

Page 13: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 13

DROP statement

Page 14: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 14

DROP statement The typical usage is simply:

• For example, the command to drop a table named employees is:

Page 15: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 15

ALTER statement

• The ALTER statement modifies an existing database object or, Alter statement is used to modify the structure of an existing object.

• Below alteration can be done on a table:o Addition of new columnso Deletion of existing columnso Changing the data type of columnso Changing the size of columns

Page 16: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 16

ALTER statement

• The typical usage is:

Page 17: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 17

ALTER statement

Note: To change the data type of a column, the column must be empty.

Page 18: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 18

RENAME statement

Rename statement is used to rename an existing object from a database

Page 19: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 19

RENAME statement

• The RENAME statement is used to rename a database table.

Page 20: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 20

TRUNCATE statement

• The TRUNCATE statement is used to delete all data from a table. It's much faster than DELETE.

Page 21: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 21

Data Manipulation Language (DML)

• A data manipulation language (DML) is a family of syntax elements similar to a computer programming language used for selecting, inserting, deleting and updating data in a database.

Page 22: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 22

Data Manipulation Language (DML) DML also known as query language

Two classes of languages Procedural – user specifies what data is

required and how to get those data Nonprocedural – user specifies what data is

required without specifying how to get those data

Page 23: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 23

Data Manipulation Language (DML)

• DML is a sub-language of SQL. It is used to manipulate the data stored in a table.

• DML provides the following statements for data manipulation:

INSERTUPDATEDELETE

Page 24: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 24

Data Manipulation Language (DML)

INSERT Statement• INSERT statement is used to insert a new

record into a table.

Page 25: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 25

Data Manipulation Language (DML)INSERT Statement

• Example• Consider a table 'EMP' having columns

named EMPNO, NAME, SAL and JOB. We can be used the below INSERT statement to insert a new record to it.

Page 26: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 26

UPDATE Statement

• Update statement is used to update an existing record in a table.

Page 27: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 27

UPDATE Statement• If the where clause of omitted, the statement

will update all the values in the particular column.

Page 28: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 28

UPDATE Statement

• Note: IS NULL is used for assignment and =NULL is used to recognize.

Page 29: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 29

DELETE Statement

• Delete Statement is used to delete records from a table.

Page 30: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 30

DELETE Statement

Page 31: Data Definition and Data Manipulation Language-DDL & DML

Md. Selim Hossain 31

DELETE Statement

• Below statement will delete all records from the table.

Page 32: Data Definition and Data Manipulation Language-DDL & DML

32Md. Selim Hossain

Thank you