0% found this document useful (0 votes)
5 views4 pages

Ex2 Dbms

The document outlines the study and implementation of Data Definition Language (DDL) commands used to define and modify database schemas. Key DDL commands include CREATE, DROP, ALTER, TRUNCATE, COMMENT, and RENAME, each with specific syntax and restrictions. The document provides examples and explanations for creating tables, altering structures, and managing database objects.

Uploaded by

VMV CREATION
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Ex2 Dbms

The document outlines the study and implementation of Data Definition Language (DDL) commands used to define and modify database schemas. Key DDL commands include CREATE, DROP, ALTER, TRUNCATE, COMMENT, and RENAME, each with specific syntax and restrictions. The document provides examples and explanations for creating tables, altering structures, and managing database objects.

Uploaded by

VMV CREATION
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No.

2
AIM: To study and implement DDL commands.
DDL (Data Definition Language):

DDL or Data Definition Language actually consists of the SQL commands that can be
used to define the database schema. It simply deals with descriptions of the database schema
and is used to create and modify the structure of database objects in the database. DDL is a set
of SQL commands used to create, modify, and delete database structures but not data. These
commands are normally not used by a general user, who should be accessing the database via
an application.

List of DDL commands:


 CREATE: This command is used to create the database or its objects (like table, index,
function, views, store procedure, and triggers).
 DROP: This command is used to delete objects from the database.
 ALTER: This is used to alter the structure of the database.
 TRUNCATE: This is used to remove all records from a table, including all spaces
allocated for the records are removed.
 COMMENT: This is used to add comments to the data dictionary.
 RENAME: This is used to rename an object existing in the database.

CREATE

The CREATE TABLE statement is used to create a new table in a database.

Syntax,

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
column3 datatype,
....
);

The column parameters specify the names of the columns of the table. The datatype parameter
specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).
Examples,

CREATE TABLE Persons (


PersonID int,
LastName varchar(25),
FirstName char(25),
Address varchar2(25),JoinDate date);

Restrictions for creating a table :

1. Table names and column names must begin with a letter.

2. Table names and column names can be 1 to 30 charcters long.

3. Table names must contain only the characters A - Z , a - z , 0 - 9 , underscore _, $ and #

4. Table names should not be same of another database object.

5. Table name must not be an ORACLE reserved word.

6. Column names should not be duplicate within a table definition.

DESCRIBE

As the name suggests, DESCRIBE is used to describe something. Since in database we have
tables, that’s why we use DESCRIBE or DESC(both are same) command to describe
the structure of a table.

DESCRIBE table_name; DESCRIBE Persons;


DESC table_name; DESC Persons;

DROP

The DROP TABLE statement is used to drop an existing table in a database.

Syntax,

DROP TABLE table_name;

Examples,

DROP TABLE Persons


ALTER

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

The ALTER TABLE statement is also used to add and drop various constraints on an existing
table.

ADD ALTER TABLE table_name ALTER TABLE Persons


ADD column_name datatype; ADD MiddleName varchar(25);
DROP ALTER TABLE table_name ALTER TABLE Persons
DROP COLUMN column_name; DROP COLUMN FirstName;
ALTER/MODIFY ALTER TABLE table_name ALTER TABLE Persons
ALTER COLUMN column_name MODIFY COLUMN FirstName
datatype; varchar(35);

Restrictions for altering the table:

1. You can add or modify column but you can’t drop it from table

2. The new column becomes last column by default

3. You can increase the width or precision of the numeric column

4. You can change the datatype if the column contains null values(column is empty)

5. Decrease the width of column if the column contains only null values or if the table has
no rows

6. You can convert a CHAR column to VARCHAR2 datatype or convert VARCHAR2


column to CHAR datatype if column contains null values or if you don’t change the size

TRUNCATE

The TRUNCATE TABLE command deletes the data inside a table, but not the table
itself.

Examples,

TRUNCATE TABLE Persons;


RENAME

Syntax,

ALTER TABLE TableName RENAME COLUMN OldColumnName TO NewColumnName;

Example,

ALTER TABLE Persons RENAME COLUMN FirstName TO FIRST_NAME;

Conclusion: Thus we have successfully studied and implemented DDL commands.

You might also like