Writeups - Assignment 2
Writeups - Assignment 2
Title: Design and Develop SQL DDL statements which demonstrate the use of SQL objects such
as Table, View, Index, Sequence, Synonym, different constraints etc.
Theory:
Structured Query Language(SQL) as we all know is the database language by the use of which
we can perform certain operations on the existing database and also we can use this language to
create a database. SQL uses certain commands like Create, Drop, Insert, etc. to carry out the
required tasks.
These SQL commands are mainly categorized into four categories as:
The DDL Commands in Structured Query Language are used to create and modify the schema of
the database and its objects. The syntax of DDL commands is predefined for describing the data.
The commands of Data Definition Language deal with how the data should exist in the database.
1. CREATE Command
2. DROP Command
3. ALTER Command
4. TRUNCATE Command
5. RENAME Command
CREATE Command
CREATE is a DDL command used to create databases, tables, triggers and other database
objects.
Examples of CREATE Command in SQL
Example 1: This example describes how to create a new database using the CREATE DDL
command.
Suppose, you want to create a Books database in the SQL database. To do this, you have to write
the following DDL Command:
Example 2: This example describes how to create a new table using the CREATE DDL
command.
...
);
Suppose, you want to create a Student table with five columns in the SQL database. To do this,
we have to write the following DDL command:
Roll_No. Int ,
Marks Int ,
);
Example 3: This example describes how to create a new index using the CREATE DDL
command.
Suppose, you want to create an index on the combination of the City and State field of
the Student table. For this, we have to use the following DDL command:
Example 4: This example describes how to create a trigger in the SQL database using the
DDL CREATE command.
Syntax to create a trigger:
[ BEFORE | AFTER ]
ON [table_name] ;
DROP Command
DROP is a DDL command used to delete/remove the database objects from the SQL database.
We can easily remove the entire table, view, or index from the database using this DDL
command.
Example 1: This example describes how to remove a database from the SQL database.
Suppose, you want to delete the Books database from the SQL database. To do this, you have to
write the following DDL command:
Example 2: This example describes how to remove the existing table from the SQL
database.
Suppose, you want to delete the Student table from the SQL database. To do this, you have to
write the following DDL command:
Example 3: This example describes how to remove the existing index from the SQL
database.
Suppose, you want to delete the index_city from the SQL database. To do this, you have to write
the following DDL command:
ALTER Command
ALTER is a DDL command which changes or modifies the existing structure of the database,
and it also changes the schema of database objects.
We can also add and drop constraints of the table using the ALTER command.
Example 1: This example shows how to add a new field to the existing table.
Suppose, you want to add the 'Father's_Name' column in the existing Student table. To do this,
you have to write the following DDL command:
Example 2: This example describes how to remove the existing column from the table.
Suppose, you want to remove the Age and Marks column from the existing Student table. To do
this, you have to write the following DDL command:
Example 3: This example describes how to modify the existing column of the existing table.
Suppose, you want to change the character size of the Last_Namefield of the Student table. To
do this, you have to write the following DDL command:
TRUNCATE Command
TRUNCATE is another DDL command which deletes or removes all the records from the table.
This command also removes the space allocated for storing the table records.
Example
Suppose, you want to delete the record of the Student table. To do this, you have to write the
following TRUNCATE DDL command:
The above query successfully removed all the records from the student table. Let's verify it by
using the following SELECT statement:
RENAME Command
RENAME is a DDL command which is used to change the name of the database table.
Example
Conclusion: Thus we have studied SQL DDL statements which demonstrate the use of SQL
objects such as Table, View, Index, Sequence
Note : use all the above commands in my sql take screen
shots of all the above commands and attach printouts.