Data Definition Language:
1 Create
2 Alter
3 Drop
4 Truncate
Create : To create the data definition.
Syntax
Create database < Database_Name >
Example
Create database Customers
Syntax for creating a Table:
-CREATE TABLE <table_name>(
column_name1 <dtype> [width],
column_name1 <dtype> [width],
………………….
column_namen <dtype> [width])
-Table names must be unique within the database.
-Column names must be unique within the table.
-Every table can have maximum of 1024 and minimum of 1 column.
The table name should start with alphabet.
Spaces and Special Symbols are not allowed.
The table name can contain max of 128 characters.
Alter:
It is used to modify the structure of the table
Using Modify Command to do the following things
1 Adding New Column
2 Drop Column
3 Modifying Column(increment, decrement field Size),(changing data type)
1 Adding New Column
Syntax:
Alter table <table name> Add <Col Name> datatype[size]
Example: Alter table students Add rollno int
2 Syntax to Drop the Column
Alter Table <Table Name> Drop column <Column Name>
Example: Alter table student Drop column studentid
3 Modifying Columns
Syntax:
Inserting the Width of the Column
Alter table <TableName> Alter Column ColName datatype
Example : Alter table <TableName> Alter Column ColName datatype
Changing the DataType of the Column
Alter table <TableName> Alter Column ColName datatype(size)
Example : Alter table Students Alter column sname varchar(20)
Drop Command: If we want to destroy the existing tables present in the database we use the Drop Command.
Syntax: DROP TABLE <TableName>
Example : Drop Table Customers
Truncate Command: Removes all rows from a table. Here the columns Remains the same so that you can add New Records in the table.
Note: We do not have Where Clause Here.
Syntax: TRUNCATE TABLE <TableName>
Example : TRUNCATE TABLE Customers
Truncate
· Truncate table is faster in execution.
· Truncate Releases Memory
· It will Reset Identity
· It Deletes all the records
Delete
· Delete table is slower in execution.
· Delete will not Releases Memory
· It will Not Reset Identity
· It deletes all the records or Particular Record.
1 Create
2 Alter
3 Drop
4 Truncate
Create : To create the data definition.
Syntax
Create database < Database_Name >
Example
Create database Customers
Syntax for creating a Table:
-CREATE TABLE <table_name>(
column_name1 <dtype> [width],
column_name1 <dtype> [width],
………………….
column_namen <dtype> [width])
-Table names must be unique within the database.
-Column names must be unique within the table.
-Every table can have maximum of 1024 and minimum of 1 column.
The table name should start with alphabet.
Spaces and Special Symbols are not allowed.
The table name can contain max of 128 characters.
Alter:
It is used to modify the structure of the table
Using Modify Command to do the following things
1 Adding New Column
2 Drop Column
3 Modifying Column(increment, decrement field Size),(changing data type)
1 Adding New Column
Syntax:
Alter table <table name> Add <Col Name> datatype[size]
Example: Alter table students Add rollno int
2 Syntax to Drop the Column
Alter Table <Table Name> Drop column <Column Name>
Example: Alter table student Drop column studentid
3 Modifying Columns
Syntax:
Inserting the Width of the Column
Alter table <TableName> Alter Column ColName datatype
Example : Alter table <TableName> Alter Column ColName datatype
Changing the DataType of the Column
Alter table <TableName> Alter Column ColName datatype(size)
Example : Alter table Students Alter column sname varchar(20)
Drop Command: If we want to destroy the existing tables present in the database we use the Drop Command.
Syntax: DROP TABLE <TableName>
Example : Drop Table Customers
Truncate Command: Removes all rows from a table. Here the columns Remains the same so that you can add New Records in the table.
Note: We do not have Where Clause Here.
Syntax: TRUNCATE TABLE <TableName>
Example : TRUNCATE TABLE Customers
Truncate
· Truncate table is faster in execution.
· Truncate Releases Memory
· It will Reset Identity
· It Deletes all the records
Delete
· Delete table is slower in execution.
· Delete will not Releases Memory
· It will Not Reset Identity
· It deletes all the records or Particular Record.
No comments:
Post a Comment
Thank you for visiting my blog