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

Database Lab 7

The document contains SQL queries for creating three tables: DeptInfo, ExamInfo, and AdmissionInfo, with appropriate primary and foreign keys. It includes sample data insertion for each table with five rows representing CS and CE students. Additionally, it outlines queries to display departmental information for CE students and student data with a GPA greater than 3.0.

Uploaded by

Mohammad Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Database Lab 7

The document contains SQL queries for creating three tables: DeptInfo, ExamInfo, and AdmissionInfo, with appropriate primary and foreign keys. It includes sample data insertion for each table with five rows representing CS and CE students. Additionally, it outlines queries to display departmental information for CE students and student data with a GPA greater than 3.0.

Uploaded by

Mohammad Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: Nouman

Reg No: FA21-BCS-233


Lab Assignment 7

Write SQL query for the following questions


1. Create table with primary and foreign keys
CREATE TABLE DeptInfo (
std_ID INT NOT NULL,
std_Name VARCHAR(255) NOT NULL,
std_Address VARCHAR(255),
std_dept VARCHAR(50),
PRIMARY KEY (std_ID)
);

CREATE TABLE ExamInfo (


std_CNIC_No VARCHAR(20) NOT NULL,
std_ID INT NOT NULL,
std_Name VARCHAR(255) NOT NULL,
std_GPA DECIMAL(3, 2),
PRIMARY KEY (std_CNIC_No),
FOREIGN KEY (std_ID) REFERENCES DeptInfo(std_ID)
);

CREATE TABLE AdmissionInfo (


enroll_No INT NOT NULL,
std_Firstname VARCHAR(255) NOT NULL,
uni_id INT NOT NULL,
enroll_date DATE,
PRIMARY KEY (enroll_No),
FOREIGN KEY (uni_id) REFERENCES DeptInfo(std_ID) -- Assuming uni_id
refers to std_ID in DeptInfo
);
2. Insert at least 5 rows in each table having CS and CE students
-- Inserting data into DeptInfo
INSERT INTO DeptInfo (std_ID, std_Name, std_Address, std_dept) VALUES
(1, 'Alice Johnson', '123 Elm St', 'CS'),
(2, 'Bob Smith', '456 Oak St', 'CE'),
(3, 'Charlie Brown', '789 Pine St', 'CS'),
(4, 'David Wilson', '321 Maple St', 'CE'),
(5, 'Eva Adams', '654 Cedar St', 'CS');

-- Inserting data into ExamInfo


INSERT INTO ExamInfo (std_CNIC_No, std_ID, std_Name, std_GPA) VALUES
('CNIC001', 1, 'Alice Johnson', 3.5),
('CNIC002', 2, 'Bob Smith', 2.8),
('CNIC003', 3, 'Charlie Brown', 3.2),
('CNIC004', 4, 'David Wilson', 3.8),
('CNIC005', 5, 'Eva Adams', 3.0);

-- Inserting data into AdmissionInfo


INSERT INTO AdmissionInfo (enroll_No, std_Firstname, uni_id, enroll_date)
VALUES
(101, 'Alice', 1, '2021-09-01'),
(102, 'Bob', 2, '2021-09-01'),
(103, 'Charlie', 3, '2021-09-01'),
(104, 'David', 4, '2021-09-01'),
(105, 'Eva', 5, '2021-09-01');
3. Display all departmental information of CE students

4. Display all student data whose GPA>3.0

You might also like