You are on page 1of 14

DATABASE MANAGEMENT LAB (CS 29006)

School of Electronics Engineering

Experiment Number 2
Experiment Title Data Definition Languages
Date of Experiment 31/01/2024
Date of Submission 13/02/2024

1. Problem Statement:

1. Use SQL statements to create the following tables in College Student Database. Define
NOT NULL DEFAULT, UNIQUE, and CHECK constraints wherever appropriate.

a) STUDENT (StudentId, Last, First, Street, City, State, Zip, StartTerm, BirthDate,
FacultyId, MajorId, Phone);
b) FACULTY (FacultyId, Name, RoomId, Phone, DeptId); COURSE (CourseId,
Title, Credits, PreReq);
c) CRSSECTION (CsId, CourseId, Section, TermId, FacultyId, Day, StratTime,
EndTime, RoomId, MaxCount);
d) TERM (TermId, TermDesc, StartDate, EndDate); ROOM (RoomType,
RoomDesc);
e) REGISTRATION (StudentId, CsId, Midterm, Final, RegStatus);
f) DEPARTMENT (DeptId, DeptName, FacultyId); MAJOR (MajorId, MajorDesc);
g) LOCATION (RoomId, Building, RoomNo, Capacity, RoomType).
Insert minimum 5 records in each table.

2. Use SQL statements to create the following tables in Corporation Employee Database.
Define NOT NULL DEFAULT, UNIQUE, and CHECK constraints wherever appropriate.

a) EMPLOYEE (EmployeeId, Lname, Fname, PositionId, Supervisor, HireDate,


Salary, Commission, DeptId, QualId); POSITION (PositionId, PosDesc);
b) DEPT (DeptId, DeptName, Location, EmployeeId); QUALIFICATION (QualId,
QualDesc); EMPLEVEL (LevelNo, LowSalary, HighSalary);
c) DEPENDENT (EmployeeId, DependentId, DepDOB, Relation).
Insert minimum 5 records in each table.

2. Theory:
The Data Definition Language (DDL) in SQL is responsible for defining and
managing the structure of a database. It includes commands like CREATE for
creating tables, indexes, and views, specifying data types and constraints. DDL also
allows modifications and deletions of database objects, ensuring tegrity and
providing a foundation for efficient data storage and retrieval

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

3. Code and Result :

create database college;


use college;

create table student(student_id int, last_name varchar(20) , first_name varchar(20),city


varchar(20),state varchar(20), zip int , start_term int , Birth_date date , faculty_id int ,
major_id int , phone int);

alter table student modify column phone long;

INSERT INTO student (student_id, last_name, first_name, city, state, zip, start_term,
Birth_date, faculty_id, major_id, phone)
VALUES
(1, 'Smith', 'John', 'New York', 'NY', 10001, 2022, '2000-01-01', 101, 201, 1234567890),
(2, 'Johnson', 'James', 'Los Angeles', 'CA', 90001, 2022, '2000-02-02', 102, 202, 2345678901),
(3, 'Williams', 'Robert', 'Chicago', 'IL', 60007, 2022, '2000-03-03', 103, 203, 3456789012),
(4, 'Brown', 'Michael', 'Houston', 'TX', 77001, 2022, '2000-04-04', 104, 204, 4567890123),
(5, 'Jones', 'William', 'Phoenix', 'AZ', 85001, 2022, '2000-05-05', 105, 205, 5678901234);

select * from student;

create table faculty(faculty_id int , name varchar(20), room_id int, phone int, dept_id int);
alter table faculty modify column phone long;

INSERT INTO faculty (faculty_id, name, room_id, phone, dept_id)


VALUES
(101, 'Smith', 101, 1234567890, 1),
(102, 'Johnson', 102, 2345678901, 2),
(103, 'Williams', 103, 3456789012, 3),

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

(104, 'Brown', 104, 4567890123, 4),


(105, 'Jones', 105, 5678901234, 5);

select * from faculty;

create table course (course_id int ,title varchar(20), credit int, pre_req varchar(20));

INSERT INTO course (course_id, title, credit, pre_req)


VALUES
(101, 'Mathematics', 3, NULL),
(102, 'Physics', 4, NULL),
(103, 'Chemistry', 4, 'yes'),
(104, 'Biology', 3, NULL),
(105, 'Computer Science', 4, 'yes');

select * from course;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

create table crssection(cs_id int ,course_id int,section varchar(5),term_id int,faculty_id int,


day date, start_time time,end_time time,room_id int,max_count int);

INSERT INTO crssection (cs_id, course_id, section, term_id, faculty_id, day, start_time,
end_time, room_id, max_count)
VALUES
(1, 101, 'A', 2022, 101, '2022-01-01', '08:00:00', '10:00:00', 101, 30),
(2, 102, 'B', 2022, 102, '2022-01-02', '10:00:00', '12:00:00', 102, 25),
(3, 103, 'C', 2022, 103, '2022-01-03', '12:00:00', '14:00:00', 103, 20),
(4, 104, 'D', 2022, 104, '2022-01-04', '14:00:00', '16:00:00', 104, 35),
(5, 105, 'E', 2022, 105, '2022-01-05', '16:00:00', '18:00:00', 105, 40);

select * from crssection;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

create table term (term_id int,term_desc varchar(20),start_date date,end_date date);

INSERT INTO term (term_id, term_desc, start_date, end_date)


VALUES
(2022, 'Spring', '2022-01-01', '2022-05-31'),
(2023, 'Autumn', '2023-06-01', '2023-08-31'),
(2023, 'Spring', '2023-09-01', '2023-12-31'),
(2023, 'Autumn', '2023-09-01', '2023-12-31'),
(2024, 'Spring', '2024-01-01', '2024-03-31');

select * from term;

create table room (room_type varchar(20),room_desc varchar(50));


Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

INSERT INTO room (room_type, room_desc)


VALUES
('Classroom', 'Large Classroom'),
('Lab', 'Computer Lab'),
('Auditorium', 'Large Auditorium'),
('Conference Room', 'Small Conference Room'),
('Office', 'Faculty Office');

select * from room;

create table registration(student_id int,cs_id int,mid_term int ,final int ,reg_status


varchar(20));

INSERT INTO registration (student_id, cs_id, mid_term, final, reg_status)


VALUES
(1, 101, 85, 90, 'Registered'),
(2, 102, 80, 85, 'Registered'),
(3, 103, 75, 80, 'Registered'),
(4, 104, 70, 75, 'Registered'),
(5, 105, 65, 70, 'Registered');

select * from registration;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

create table department(dept_id int ,dept_name varchar(50),faculty_id int );


INSERT INTO department (dept_id, dept_name, faculty_id)
VALUES
(1, 'Computer Science', 101),
(2, 'Mechanical Engineering', 102),
(3, 'Electrical Engineering', 103),
(4, 'Civil Engineering', 104),
(5, 'Chemical Engineering', 105);

select * from department;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

create table location(room_id int,building varchar(20), room_no varchar(6),capacity


int,room_type varchar(20));

INSERT INTO location (room_id, building, room_no, capacity, room_type)


VALUES
(101, 'Building A', '101', 30, 'Classroom'),
(102, 'Building B', '102', 25, 'Lab'),
(103, 'Building C', '103', 20, 'Auditorium'),
(104, 'Building D', '104', 35, 'Conference Room'),
(105, 'Building E', '105', 40, 'Office');

select * from location;

create database corporation;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

use corporation;

Create table employee( employee_id INT not null primary key, lname VARCHAR(20),
fname VARCHAR(20), position_id INT,supervisor VARCHAR(20), hire_date DATE,
salary FLOAT, commission FLOAT, dept_id INT, qual_id INT);

Insert into employee (employee_id, lname, fname, position_id, supervisor, hire_date,


salary, commission, dept_id, qual_id)
Values
(1, 'Smith', 'John', 1, 'Johnson', '2022-01-01', 50000, 0.1, 1, 1),
(2, 'Johnson', 'Jane', 2, 'Smith', '2022-02-01', 60000, 0.15, 2, 2),
(3, 'Williams', 'Jim', 3, 'Brown', '2022-03-01', 70000, 0.2, 3, 3),
(4, 'Brown', 'Jill', 4, 'Taylor', '2022-04-01', 80000, 0.25, 4, 4),
(5, 'Taylor', 'Jack', 5, 'Miller', '2022-05-01', 90000, 0.3, 5, 5);

Select * from employee;

Create table Psition(position_id INT, pos_desc VARCHAR(20));

Insert into Psition (position_id, pos_desc)


Values
(1, 'Manager'),
(2, 'Assistant Manager'),
(3, 'Lead'),
(4, 'Senior Developer'),
(5, 'Junior Developer');

Select * from pstion;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

Create table dept(dept_id INT, dept_name VARCHAR(20), location VARCHAR(50),


employee_id INT);

Insert into dept (dept_id, dept_name, location, employee_id)


Values
(1, 'HR', 'Building A', 1),
(2, 'Sales', 'Building B', 2),
(3, 'Marketing', 'Building C', 3),
(4, 'Finance', 'Building D', 4),
(5, 'IT', 'Building E', 5);

Select * from dept;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

Create table qualification( qual_id INT, qual_desc VARCHAR(50));

Insert into qualification (qual_id, qual_desc)


Values
(1, 'Bachelor\'s Degree'),
(2, 'Master\'s Degree'),
(3, 'PhD'),
(4, 'Associate Degree'),
(5, 'High School Diploma');

Select * from qualification;

Create table emplevel(level_no INT,low_salary FLOAT,high_salary FLOAT);

Insert into emplevel (level_no, low_salary, high_salary)


Values
(1, 30000, 40000),
(2, 40000, 50000),
(3, 50000, 60000),
(4, 60000, 70000),
(5, 70000, 80000);

Select * from emplevel;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

Create table dependent( employee_id INT, dependent_id INT, dep_dob DATE, relation
VARCHAR(20));

Insert into dependent (employee_id, dependent_id, dep_dob, relation)


Values
(1, 101, '2010-01-01', 'Child'),
(2, 102, '2011-02-01', 'Spouse'),
(3, 103, '2012-03-01', 'Child'),
(4, 104, '2013-04-01', 'Child'),
(5, 105, '2014-05-01', 'Spouse');

Select * from dependent;

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

4. Concluding Remarks:

The Data Definition Language (DDL) in SQL is responsible for defining and
managing the structure of a database. It includes commands like CREATE for
creating tables, indexes, and views, specifying data types and constraints.
DDL also allows modifications and deletions of database objects, ensuring
data integrity and providing a foundation for efficient data storage and
retrieval.

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030
DATABASE MANAGEMENT LAB (CS 29006)
School of Electronics Engineering

Submitted by:
Name: Nikhil Kumar
Roll No.: 2230030

You might also like