Experiment No. 5: Aim: To Study and Implement DATA DEFINITION LANGUAGE (DDL) COMMANDS
Experiment No. 5: Aim: To Study and Implement DATA DEFINITION LANGUAGE (DDL) COMMANDS
Part A:
Theory:
SQL language is divided into four types of primary language statements: DML, DDL, DCL and TCL.
Using these statements, we can define the structure of a database by creating and altering database
objects, and we can manipulate data in a table through updates or deletions. We also can control
which user can read/write data or manage transactions to create a single unit of work.
DML statements affect records in a table. These are basic operations we perform on data such as
selecting a few records from a table, inserting new records, deleting unnecessary records, and
updating/modifying existing records.
DDL statements are used to alter/modify a database or table structure and schema. These statements
handle the design and storage of database objects.
DCL statements control the level of access that users have on database objects.
TCL statements allow you to control and manage transactions to maintain the integrity of data within
SQL statements.
SQL Commands:
Syntax: Create table tablename (column_name1 data_ type constraints, column_name2 data_ type
constraints …)
Example: Create table Emp ( EmpNo number(5), EName VarChar(15), Job Char(10) constraint un
unique, DeptNo number(3) CONSTRAINT FKey2 REFERENCES DEPT(DeptNo)); Create table
stud (sname varchar2(20) not null, rollno number(10) not null,dob date not null);
Rules:
ALTER TABLE:
It is used to:
Example:
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;
Example: Truncate table stud;
DESC
--------------------------------- --------
EName VarChar(15)
DOMAIN INTEGRITY
Example: Create table student (regno number (6), mark number (3) constraint b check (mark >=0 and
mark <=100));
ENTITY INTEGRITY
Example: Create table cust(custid number(6) constraint uni unique, name char(10));
Example: Create table stud(regno number(6) constraint primary key, name char(20));
Part B:
Query:
Screenshot of output:
Conclusion: