Ex: NO:1 SQL QUERIES FOR CREATION OF DATABASE

Aim:

To execute the queries to create and alter the schema of the database.

Data Definition in SQL
Creating Tables:

The SQL command for creating an empty table has the following form:

Syntax:

create table <table-name> (<column 1> <data type> ,<column2t> <data type>, . . . , .<column n> <data type>, <integrity constraint1>,…., <integrity constraint n>);

Example:

The create table statement for EMP table has the form

create table EMP (EMPNO number(4), ENAME varchar2(30), JOB varchar2(10), MGR number(4), HIREDATE date, SAL number(7,2), DEPTNO number(2));

Deleting tables:

The following command will drop the table from the database.

Syntax:

drop table <table-name>;

Example:

drop table emp;

Alter table:

Alter table command is used to add, modify or drop attributes  or columns from the table.

Syntax:

alter table <table-name> add/modify <col-name1> <datat ype>,….,<col-namen> <data type>;

alter table <table-name> drop <col-nmae>;

Example:

alter table emp add year char(3);

Truncate table:

The truncate table command deletes the rows in the table but retains the table structure.

Syntax:

truncate table <table-name>;

Example:

truncate table emp;

Describe table:

This command is used to view the schema of the table

Syntax:

desc <table-name>;

Result:

The commands to create and alter the schema of the database are executed.

Leave a Reply

Your email address will not be published. Required fields are marked *