AK2DBMS
AK2DBMS
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:
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:
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