DDL Command Information and Syntax... Assignment 1
DDL Command Information and Syntax... Assignment 1
);
Command-2 :
ALTER :
This command is used to add, delete or change
columns in the existing table. The user needs to know
the existing table name and can do add, delete or
modify tasks easily.
Syntax –
Syntax to add a column to an existing table.
ALTER TABLE table_name
ADD column_name datatype;
Example –
In our Student_info table, we want to add a new
column for CGPA. The syntax would be as below as
follows.
ALTER TABLE Student_info
ADD CGPA number;
Command-3 :
TRUNCATE :
This command is used to remove all rows from the
table, but the structure of the table still exists.
DDL COMMAND WITH SYNTAX ,EXAMPLES, INFORMATION
Syntax –
Syntax to remove an existing table.
TRUNCATE TABLE table_name;
Example –
The College Authority wants to remove the details of
all students for new batches but wants to keep the
table structure. The command they can use is as
follows.
TRUNCATE TABLE Student_info;
Command-4 :
DROP :
This command is used to remove an existing table
along with its structure from the Database.
Syntax –
Syntax to drop an existing table.
DROP TABLE table_name;
Example –
If the College Authority wants to change their Database
by deleting the Student_info Table.
DROP TABLE Student_info;
DDL COMMAND WITH SYNTAX ,EXAMPLES, INFORMATION
Command Description
table.
);
2. ALTER
ALTER command in SQL is used to add, rename or
modify, drop/delete columns in an existing database
table. It can further be used to add and remove various
constraints on an existing database table.
The syntax used for altering a table in SQL by adding a
new column is as follows :
ALTER TABLE table_name
ADD (Columnname_1 datatype)
Here is an example to add a new column to an existing
table.
ALTER TABLE customer_details
ADD email_address character varying(255);
3. TRUNCATE
TRUNCATE TABLE command is used to remove all the
data records from the database table. It deletes all the
rows permanently. Ergo, we cannot perform a rollback
operation to undo a TRUNCATE command.
DDL COMMAND WITH SYNTAX ,EXAMPLES, INFORMATION