SQL SEVER
• Data Definition Language (DDL) : are used to define the
database structure or schema.
– Create – Drop
– Alter – Truncate
• Data Manipulation Language (DML) : are used for managing
data within schema objects.
– Insert – Delete
– Update – SELECT
• Data Control Language (DCL) statements : Used to create
roles, permissions, and referential integrity as well it is used
to control access to database by securing it.
– Grant
– Revoke
– Commit
– Rollback
DDL STATEMENTS
Create - Database
• To create a Database
– Syntax : CREATE DATABASE dbname;
– Example : CREATE DATABASE my_db;
• To Use a database
– Syntax : Use dbname;
– Example : Use my_db;
Creating a table
• Syntax • Example
CREATE
TABLE table_name CREATE TABLE Persons
( (
column_name1 PersonID int
data_type(size), identity(1,1),
column_name2 FirstName varchar(255),
data_type(size), Address varchar(255),
column_name3 City varchar(255),
data_type(size), Primary key(PersonalID)
PRIMARY );
KEY(column_name1));
DDL - Altering a table
• ALTER TABLE Persons ADD email VARCHAR(60);
• ALTER TABLE Persons DROP COLUMN city;
• ALTER TABLE Persons CHANGE FirstName FullName
VARCHAR(20);
DDL - Deleting a Table
• DROP TABLE table_name ;
DML - Examples