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

AK2DBMS

The document outlines the procedures for implementing Data Definition Language (DDL) commands in SQL to create and manage database objects. It includes steps for creating tables, defining primary and foreign keys, modifying table structures, adding constraints, and ensuring data integrity. The document also emphasizes the importance of validating the results and documenting the SQL queries used.

Uploaded by

thebersek47
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

AK2DBMS

The document outlines the procedures for implementing Data Definition Language (DDL) commands in SQL to create and manage database objects. It includes steps for creating tables, defining primary and foreign keys, modifying table structures, adding constraints, and ensuring data integrity. The document also emphasizes the importance of validating the results and documenting the SQL queries used.

Uploaded by

thebersek47
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

Ex.

no: 2
QUERIES TO IMPLEMENT DATA DEFINITION
Date: LANGUAGE COMMANDS

AIM:
To write SQL queries for creating and managing database objects using Data Definition
Language (DDL) commands.

Procedure:
1. Use the CREATE TABLE command to create tables with appropriate columns and data types.
2. Define primary keys and foreign keys to establish relationships.
3. Use the ALTER TABLE command to modify the structure of existing tables.
4. Add constraints such as NOT NULL, UNIQUE, and CHECK to the columns.
5. Use the DROP TABLE command to delete tables if needed.
6. Ensure data integrity by defining referential actions such as ON DELETE CASCADE.
7. Verify the creation of tables by querying the database metadata.
8. Document the SQL queries used for each step.
9. Execute the queries in the SQL environment.
10. Validate the results by checking the structure of the created tables.

Queries:

1. Create Tables with Appropriate Columns and Data Types:


CREATE TABLE Employees
( EmployeeID INT PRIMARY
KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
BirthDate DATE,
DepartmentID INT
);
Output:

2. CREATE TABLE Departments ( DepartmentID INT PRIMARY KEY, Define Primary Keys and
Foreign Keys to Establish Relationships:
ALTER TABLE Employees
ADD CONSTRAINT FK_Department
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID);
Output:

717823D104-AKHILESH.R 23CSR302-DATABASEMANAGEMENTSYSTEM
3. Modify the Structure of
Existing Tables:
ALTER TABLE Employees
ADD Email VARCHAR(100);
ALTER TABLE Departments
ADD Location VARCHAR(100);
Output:

Add Constraints such as NOT NULL, UNIQUE, and CHECK:


4.
ALTER TABLE Employees
MODIFY Email VARCHAR(100) NOT NULL;
ALTER TABLE Employees ADD CONSTRAINT CHK_BirthDate
CHECK (BirthDate <= TO_DATE('2005-01-01', 'YYYY-MM-DD'));
Output:

Delete Tables if Needed:


5.
DROP TABLE Employees;
DROP TABLE Departments;
Output:

Ensure Data Integrity by Defining Referential Actions:


6.
ALTER TABLE Employees
ADD CONSTRAINT FK_Department
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
ON DELETE CASCADE;
Output:

717823D104-AKHILESH.R 23CSR302-DATABASEMANAGEMENTSYSTEM
10. Validate the Results by Checking the Structure of the Created Tables:
DESCRIBE Employees;
DESCRIBE Departments;

Output:

Results:
Thus, Tables Employees and Departments created successfully with the defined structure and
constraints.

717823D104-AKHILESH.R 23CSR302-DATABASEMANAGEMENTSYSTEM

You might also like