Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

LIST OF EXPERIMENTS

1. Creating database, table


2. Working with Data Manipulation commands
3. Basic SELECT statements
4. Advanced SELECT statements
5. Integrity and Constraints
6. Joining Tables
7. SQL functions
8. Sub queries
9. Views
10. Basics of PL/SQL
11. Design and Develop applications
DATA DEFINITION LANGUAGE (DDL) COMMANDS IN RDBMS

AIM:
To execute the various Data Definition Language commands in RDBMS.
OBJECTIVE:
After completing the exercise the students can able to Understand how to create a table
with list of fields, Modify a row using where clause, Drop a table, Delete the unwanted rows in a
table.
DATA DEFINITION LANGUAGE
It is used to communicate with database.
DDL is used to:
Create an object
Alter the structure of an object
To drop the object created.
ALGORITHM:
Step 1: Start the program
Step 2: Go to SQL.
Step 3: Enter the user name and password.
Step 4: Connect to the database.
Step 5: Type the commands for creating tables and perform various operations on the tables.
Step 6: The output is displayed.
Step 7: Stop the program
DDL COMMAND:
CREATE
ALTER
DROP
TRUNCATE
RENAME

CREATE TABLE
QUERY: 01
Q1: Write a query to create a table employee with empno, ename, designation, and salary.
Syntax: It is used to create a table
SQL: CREATE TABLE <TABLE NAME>(COLUMN NAME.1 <DATATYPE> (SIZE),
COLUMN NAME.2 <DATATYPE> (SIZE) ………);
Command:
SQL>CREATE TABLE EMP (EMPNO INT,ENAME VARCHAR
(10),DESIGNATIN VARCHAR (10),SALARY INT);

Table created.

TABLE DESCRIPTION
It is used to view the table structure to confirm whether the table was createdcorrectly.
QUERY: 02
Q2: Write a query to display the column name and data type of the table employee.
Syntax: This is used to view the structure of the table.
SQL: DESC <TABLE NAME>;
Command:
SQL> DESC EMP;
Name Null? Type
--------------- ----------------
EMPNO INT
ENAME VARCHAR2(10)
DESIGNATINVARCHAR2(10)
SALARY INT
QUERY: 03
Q3: Write a query for create a from an existing table with all the fields
Syntax: syntax for create a table from an existing table with all fields.
SQL> CREATE TABLE <TRAGET TABLE NAME> AS SELECT * FROM<SOURCE
TABLE NAME>;
Command:
SQL> CREATE TABLE EMP1 AS SELECT * FROM EMP;
Table created.
Command:

SQL> DESC EMP1

Name Null? Type


---------------- --------------------------
EMPNO INT
ENAME VARCHAR2(10)
DESIGNATIN VARCHAR2(10)
SALARY INT

QUERY: 04

Q4: Write a query for create a table from an existing table with selected fields
Syntax: Syntax for create a from an existing table with selected fields.
SQL> CREATE TABLE <TRAGET TABLE NAME> AS SELECT EMPNO, ENAMEFROM
<SOURCE TABLE NAME>;
Command:
SQL> CREATE TABLE EMP2 AS SELECT EMPNO, ENAME FROM EMP;
Table created.

Command:
SQL> DESC EMP2
Name Null? Type
----------------- --------------------- ----
EMPNO INT
VARCHAR2
ENAME (10)

QUERY: 05
Q5: Write a query for create a new table from an existing table without any record:
Syntax: The syntax for create a new table from an existing table without any record.
SQL> CREATE TABLE <TRAGET TABLE NAME> AS SELECT * FROM<SOURCE
TABLE NAME>
WHERE <FALSE CONDITION>;
Command:
SQL> CREATE TABLE EMP3 AS SELECT * FROM EMP WHERE1>2;
Table created.
Command:

SQL> DESC EMP3;


Name Null? Type
------------------ -----------------------
EMPNO INT
ENAME VARCHAR2(10)
DESIGNATIN VARCHAR2(10)
SALARY INT(

ALTER & MODIFICATION ON TABLE


To modify structure of an already existing table to add one more columns and also
modify the existing columns.
Alter command is used to:
 Add a new column.
 Modify the existing column definition.
 To include or drop integrity constraint.
QUERY: 06
Q6: Write a Query to Alter the column ENAME VARCHAR (10) TO ENAME VARCHAR (20)
Syntax: The syntax for alter & modify on a single column.
SQL > ALTER <TABLE NAME> MODIFY <COLUMN NAME><DATATYPE>(SIZE);
Command:
SQL>ALTER TABLE EMP MODIFY EMPNO NUMBER (6);
Table altered.
Command:
SQL> DESC EMP;
Name Null? Type
----------------- ----------------------------------
EMPNO INT
ENAME VARCHAR2(20)
DESIGNATIN VARCHAR2(10)
SALARY INT

QUERY:7
Q7. Write a Query to Alter the table employee with multiple columns (EMPNO,ENAME.)
Syntax: To alter table with multiple column.
SQL > ALTER <TABLE NAME> MODIFY <COLUMN NAME1><DATATYPE>(SIZE),
MODIFY <COLUMN NAME2><DATATYPE>(SIZE)………….;
Command:
SQL>ALTER TABLE EMP MODIFY (EMPNO NUMBER (7),
ENAMEVARCHAR2(12)); Table altered.

Command:
SQL> DESC EMP;
Name Null? Type
----------------- -------------------------------
EMPNO INT
ENAME VARCHAR2(12)
DESIGNATINVARCHAR2(10)
SALARY INT
QUERY: 08
Q8. Write a query to add a new column in to employee
Syntax: To add a new column.
SQL> ALTER TABLE <TABLE NAME> ADD (<COLUMN
NAME><DATATYPE><SIZE>);
Command:
SQL> ALTER TABLE EMP ADD QUALIFICATION (VARCHAR2(6));
Table altered.
SQL> DESC EMP;
Name Null? Type
---------------- ------------------------
EMPNO INT
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY INT
QUALIFICATION VARCHAR2(6)
QUERY: 09
Q9: Write a query to add multiple columns in to employee
Syntax: Syntax for add a new column.
SQL>ALTERTABLE<TABLENAME>ADD(<COLUMNNAME1><DATATYPE><SIZE>,
(<COLUMN NAME2><DATA TYPE><SIZE>…);
Command:
SQL>ALTER TABLE EMP ADD (DOB DATE, DOJ DATE);
Table altered.
SQL> DESC EMP;
Name Null? Type
----------------- --------------------------------
EMPNO INT
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY INT
QUALIFICATION VARCHAR2(6)
DOB DATE
DOJ DATE
REMOVE / DROP
It will delete the table structure provided the table should be empty.

QUERY: 10

Q10. Write a query to drop a column from an existing table employee


Syntax: syntax for add a new column.
SQL> ALTER TABLE <TABLE NAME> DROP COLUMN <COLUMN NAME>;
Command:
SQL> ALTER TABLE EMP DROP COLUMN DOJ;
Table altered.
SQL> DESC EMP;
Name Null? Type
----------------- ----------------------------
--
EMPNO INT
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY INT
QUALIFICATION VARCHAR2(6)
DOB DATE
QUERY: 11
Q10. Write a query to drop multiple columns from employee
Syntax:The Syntax for add a new column.
SQL> ALTER TABLE <TABLE NAME> DROP <COLUMNNAME1>,<COLUMN
NAME2>,……….. ;
Command:
SQL> ALTER TABLE EMP DROP (DOB, QUALIFICATION);
Table altered.
SQL> DESC EMP;
Name Null? Type
------------------ ---------------------------
EMPNO INT
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY INT
QUERY: 12: RENAME
Q10. Write a query to rename table emp to employee
Syntax:The Syntax for add a new column.
SQL>RENAME <OLD NAME> TO <NEW NAME>
Command:
SQL> RENAME EMP TO EMPLOYEE;
SQL> DESC EMPLOYEE;
Name Null? Type
------------------- ----------------------
EMPNO INT
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY INT
TRUNCATE TABLE
If there is no further use of records stored in a table and the structure has to be retained
then the records alone can be deleted.
Syntax:
TRUNCATE TABLE <TABLE NAME>;
Example:
Truncate table EMP;
DROP:
To remove a table along with its structure and data.
Syntax:The Syntax for add a new column.
SQL> Drop table<table name>;
Command:
SQL> drop table employee;

RESULT

Thus the DDL commands were executed successfully and verified.

You might also like