0% found this document useful (0 votes)
7 views10 pages

Lab 3 Report

This lab report focuses on Data Definition Language (DDL) in SQL, detailing various operations on database tables such as creating, altering, and deleting attributes. It includes SQL code examples for modifying a 'Customer' table, managing a 'Product' table, and creating and updating a 'Student' table. The report is submitted by Muhammad Rehan Umar for a Computer Engineering course at the University of Engineering and Technology, Taxila.
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)
7 views10 pages

Lab 3 Report

This lab report focuses on Data Definition Language (DDL) in SQL, detailing various operations on database tables such as creating, altering, and deleting attributes. It includes SQL code examples for modifying a 'Customer' table, managing a 'Product' table, and creating and updating a 'Student' table. The report is submitted by Muhammad Rehan Umar for a Computer Engineering course at the University of Engineering and Technology, Taxila.
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/ 10

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

FACULTY OF TELECOMMUNICATION AND INFORMATION


ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

DATABASE AND MANAGEMENT SYSTEM

LAB REPORT 03

Topic : DDL

Submitted BY: MUHAMMAD REHAN UMAR

Submitted TO: SIR SHAHID BHUTTA

Roll No : (22-CP-72)

Semester : 6th
Section : OMEGA
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

1): Consider the following table:

• Write an SQL statement to convert the above table into following


table.

• Write SQL statement(s) to change “Birth_Date” to “Age” with data


type Integer.

• Create an Index on the “Customer” table using “First_Name” and


“Age”.

• Add a new attribute Supplier_Name into table.


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

CODE :
CREATE TABLE CUSTOMER(

FIRST_NAME CHAR(50),

LAST_NAME CHAR(50),

ADDRES CHAR (50),

CITY CHAR(50),

COUNTRY CHAR(50),

BIRTH_DATE DATETIME

SELECT * FROM CUSTOMER

CODE :
ALTER TABLE CUSTOMER

ADD GENDER CHAR(1);

SELECT * FROM CUSTOMER

OUTPUT:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

CODE:
ALTER TABLE CUSTOMER

ADD GENDER CHAR(1);

SP_RENAME 'CUSTOMER.BIRTH_DATE' , 'AGE';

ALTER TABLE CUSTOMER

ALTER COLUMN AGE VARCHAR(50);

ALTER TABLE CUSTOMER

ALTER COLUMN AGE INT;

CREATE INDEX C_INDEX

ON CUSTOMER (FIRST_NAME,AGE);

SELECT * FROM CUSTOMER

OUTPUT:

CODE:
ALTER TABLE CUSTOMER

ADD SUPPLIER_NAME VARCHAR(50);

SELECT * FROM CUSTOMER


UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

2): Consider the following


table“Product”:

1)Write an SQL statement to delete the “ProductName” entries from the table.

CODE:
CREATE TABLE Product(

ProductID int,

ProductName varchar(255),

SupplierID int,

CategoryID int,

unit varchar(255),

Price decimal(10,2)

INSERT INTO Product VALUES (1,'Chasis',1,1,'10 boxes X 20 bags', 18)

INSERT INTO Product VALUES (2,'Chang',1,1,'24 - 12 oz bottles', 19)

INSERT INTO Product VALUES (3,'Aniseed Syrup',1,2,'12 - 550 ml bottles', 10)

INSERT INTO Product VALUES (4,'Chef Anton''s Cajun Seasoning',1,2,'48 - 6 oz jars', 22)

INSERT INTO Product VALUES (5,'Chef Anton''s Gumbo Mix',1,2,'36 boxes', 21.35)

UPDATE Product

SET ProductName = NULL;

SELECT * FROM Product;

OUTPUT :
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

3): Consider the following tables:

Student

Student_ID Student_Name

38214 Ali

54907 Ahsan

66324 Bilal

70542 Naeem

Create the above table by keeping their first columns as primary key. After the
creation of the table, solve the following:

• Write a query to add an attribute, Class to the Student table

• Write a query to change the field for Student_Name from 25


characters to 40 characters

• Write a query to add another column in the Student table with an


auto increment field

• Write a query to add another column Department in the Student


table. The column must not contain any value other than the values
COMPUTER or SOFTWARE
• Write a query to change the auto increment field to start from 50
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

• Write a query to remove the Student table

CODE:
CREATE TABLE Student(

Student_ID int PRIMARY KEY,

Student_Name varchar(200),

);

INSERT INTO Student VALUES (38214,'Ali');

INSERT INTO Student VALUES (54907,'Ahsan');

INSERT INTO Student VALUES (66324,'Bilal');

INSERT INTO Student VALUES (70542,'Naeem');

OUTPUT:

CODE:
ALTER TABLE Student

ADD Class varchar(50);

ALTER TABLE Student

ALTER COLUMN Student_Name varchar(40);

OUTPUT:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

CODE:
ALTER TABLE Student

ADD Roll_No int IDENTITY;

OUTPUT:

CODE:
ALTER TABLE Student

ADD Department VARCHAR(50)

CHECK (Department IN ('COMPUTER', 'SOFTWARE'));

OUTPUT:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

CODE:
ALTER TABLE Student

DROP COLUMN Roll_No;

OUTPUT:

CODE:
ALTER TABLE Student

ADD Roll_No int IDENTITY(50, 1);

OUTPUT:
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION
ENGINEERING

COMPUTER ENGINEERING DEPARTMENT

CODE:
DROP TABLE Student;

You might also like