+1 vote
in Class 12 by kratos

Explain DDL commands with example.

1 Answer

+3 votes
by kratos
 
Best answer

DDL -Data Definition Language commands create database objects such as tables, views, etc., The various DDL commands are Create Table, Alter Table, Create View, Drop Table.
-Create Table
SYNTAX:
CREATE TABLE table_name
( field1 datatype [ NOT NULL ],
field2 datatype [ NOT NULL ],
field3 datatype [ NOT NULL ]…)
An example of a CREATE TABLE statement follows.
SQL> CREATE TABLE BILLS (2 NAME CHAR(30),

3 AMOUNT NUMBER,
4 ACCOUNT_ID NUMBER);

The ALTER TABLE command is used to do two things:

  • Add a column to an existing table
  • Modify a column that already exists

SYNTAX:

ALTER TABLE table_name ADD( column_name data_type);
ALTER TABLE table_name MODIFY (column_name data_type);
The following command changes the NAME field of the BILLS table to hold 40 characters:
SQL> ALTER TABLE BILLS MODIFY (NAME CHAR(40));

DROP command is used to remove the entire table from the database.
syntax:
DROP TABLE tablename;
Example:
DROP TABLE student;

...