0% found this document useful (0 votes)
11 views9 pages

02 134222 107 119459103194 05052024 034404pm 3

Uploaded by

usmanugly
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)
11 views9 pages

02 134222 107 119459103194 05052024 034404pm 3

Uploaded by

usmanugly
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/ 9

NAME: TALHA HAIDER.

CLASS: BSCS 4-B.


ENROLLMENT: 02-134222-107.
DBMS LAB 8 TASKS
TASK 1:
Create a replica of Teacher table with all the records in it.
select * into clone_teacher from Teacher;
select * from clone_teacher;

TASK 2:
Create a replica of Std table with all the students that belong to BSCS program
select *
into clone_std
from std
where ProgID = (select ProgID from prog where ProgName like 'BSCS' );
select * from clone_std;
NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 3:
Add a column ‘Address’ in replicated Teacher Table.

alter table clone_teacher


add Address varchar(50);
select * from clone_teacher;

TASK 4:
Drop column ‘Address’ from replicated table.

alter table clone_teacher drop column Address


select * from clone_teacher
NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 5:
Add columns ‘House No’ character ,’Street No’ numeric, ’Area’ character ,’City’ character in
replicated Teacher Table with the respective data types.

alter table clone_teacher


add HouseNo varchar(50),StreetNo int,Area varchar(50),city varchar(50)
select * from clone_teacher

TASK 6:
Change the data type of ‘House No’ from character to numeric.

alter table clone_teacher alter column HouseNo int


NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 7:
Create the Data Definitions for each of the relations shown below, using SQL DDL.
Assume the following attributes and data types: …………………….
create table Faculty(
FacultyID int,
FacultyName varchar(25),
primary key (FacultyID)
);
create table Ccourse(
CourseID varchar(8),
CourseName varchar(25),
primary key (CourseID)
);
create table Class(
ClassID int,
CourseID varchar(8),
SectionNo int,
Semester varchar(10),
primary key (ClassID),
Foreign key (CourseID) references Ccourse(CourseID),

);

create table Student(


StudentID int,
StudentName varchar(25),
FacultyID int,
primary key (StudentID),
Foreign key (FacultyID) references Faculty(FacultyID),
);
NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 8:
Add an attribute, Class and Phone to the STUDENT table.
alter table student
add class varchar(50),Phone varchar(11)
select * from Student

TASK 9:
Change StudentName size from 25 characters to 20 characters

alter table student


alter column StudentName varchar(20)
NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 10:
Remove all records from student table.

delete from student


select * from Student

TASK 11:
Remove newly created Faculty and Course tables
NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 12:
Create a table DEPARTMENT with the following attributes:
DEPTNO int, DNAME varchar(10), LOC varchar(10).
Apply PRIMARY KEY constraint on DEPTNO.

CREATE TABLE DEPARTMENT (


DEPTNO INT PRIMARY KEY,
DNAME VARCHAR(10),
LOC VARCHAR(10)
);
select * from DEPARTMENT

TASK 13:
Create a table EMPLOYEE with the following attributes:
EMPNO int, ENAME varchar(10),SAL int, DEPTNO int.
Apply FOREIGN KEY constraint on DEPTNO referencing the DEPARTMENT table
created in question 1 and PRIMARY KEY constraint on EMPNO.

create table Employee


(EMPNO int, ENAME varchar(10), SAL int, DEPTNO int,
constraint pk_EMPNO primary key(EMPNO),
constraint fk_DEPTNO foreign key (DEPTNO)
references DEPARTMENT (DEPTNO))

select * from Employee


NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 14:
ALTER table EMPLOYEE created in question 2 and apply the constraint CHECK on ENAME
attribute such that ENAME should always be inserted in capital letters.

alter table employee


add constraint CHK_EMPLOYEE_ENAME_CAPS
check (ENAME = UPPER(ENAME));

TASK 15:
ALTER table DEPARTMENT created in question 1 and apply constraint on DNAME such that
DNAME should not be entered empty.

alter table DEPARTMENT


add constraint CHK_DNAME_NOT_EMPTY
check (DNAME is not null)
NAME: TALHA HAIDER.
CLASS: BSCS 4-B.
ENROLLMENT: 02-134222-107.

TASK 16:
ALTER table EMPLOYEE created in question 2 and apply the constraint on SAL attribute such
that no two salaries of the employees should be similar.

alter table EMPLOYEE


add constraint unq_sal unique(SAL)

TASK 17:
ALTER table DEPARTMENT created in question 1 and apply the constraint on DNAME such
that no 2 Department are of the same name

alter table DEPARTMENT


add constraint unq_dname unique(DNAME)

You might also like