SQL statements DDL (data Definition Language)
SQL Statements :
SQL comprises four
main language statements :
Which are
DDL(Data definition
language)
DML(Data manipulation
language)
DCL (Data
Control Language)
TCL (Transaction
Control Language)
In this blog, I’ll discuss the first
sublanguage of SQL which is DDL from where the whole process of creating
a database is started.
How to create the SQL statement:
There are certain rules that must be
followed to create precise SQL statements. Each and every SQL sublanguage have
its own statements as shown in the above picture. So let’s see the DDL
statements.
DDL(Data Definition Language):
DDL is a language that
is used to create the structure of the database and then later on the user can alter
the table if required.
§
SQL Create Table Statement:
Create statement is used to create a
new table .it’s syntax is as follows.
CREATE
TABLE table_name (column1 datatype, column2 datatype, columns datatype);
Where N is a variable number of columns
and datatype specifies the type of data to be stored in the column.
Example:
This statement will create a table The department that has 3 columns Dept_ID,
Dept Name and Location.
§ SQL Alter table statements:
Alter table statement is used to add
or drop or modify a column in an existing table. It is used to change the data type of an existing field of a table. Its syntax is as follows.
Syntax To Add A New Column :
ALTER TABLE table_name
ADD column_name
datatype;
Example:
ALTER TABLE Department
ADD City
varchar(255);
Syntax to Delete An Existing Column :
ALTER TABLE table_name
DROP COLUMN column_name ;
Example:
ALTER TABLE Department
DROP COLUMN Location ;
Syntax to modify the datatype of an
existing column.
ALTER TABLE table_name
MODIFY column_name
datatype ;
Example:
ALTER TABLE Department
MODIFY (City
CHAR(27)) ;
§ SQL Drop Table Statement :
The Drop the statement is used to delete a table along with its structure, attributes and
indexes. The syntax is as follows:
DROP TABLE table_name ;
Example:
DROP TABLE Department ;
§ SQL Truncate Table :
The TRUNCATE TABLE STATEMENT is
used to delete all the data in a table. However, it doesn’t delete the structure
of a table. The syntax is:
TRUNCATE TABLE table_name ;
Example:
TRUNCATE TABLE Department ;
Comments
Post a Comment
your feedback is valuable.