0% found this document useful (0 votes)
3 views

20234103222_lab2

The document outlines the SQL commands for creating a database named 'University' with tables for Department, Student, Course, and Result, including their respective fields and constraints. It also includes several INSERT statements to add data to these tables, along with error messages indicating duplicate entries. Finally, it lists various SELECT queries to retrieve information from the database.

Uploaded by

Arifur Rahman
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)
3 views

20234103222_lab2

The document outlines the SQL commands for creating a database named 'University' with tables for Department, Student, Course, and Result, including their respective fields and constraints. It also includes several INSERT statements to add data to these tables, along with error messages indicating duplicate entries. Finally, it lists various SELECT queries to retrieve information from the database.

Uploaded by

Arifur Rahman
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/ 3

1.

​ CREATE DATABASE University

CREATE TABLE Department


(
​ Department_ID INT,
Name VARCHAR(15) PRIMARY KEY,
Building INT,
Estalish_Year DATE
);

CREATE TABLE Student


(
​ Student_ID INT PRIMARY KEY,
Name VARCHAR(20),
CGPA FLOAT,
Dept VARCHAR(15),
Hometown VARCHAR(20),

CONSTRAINT ref_dept_by FOREIGN KEY(Dept) REFERENCES Department(Name)


);

CREATE TABLE Course


(
Course_Code INT PRIMARY KEY,
Name VARCHAR(20),
Credit FLOAT,
Dept VARCHAR(15),
CONSTRAINT ref_cdept_by FOREIGN KEY(Dept) REFERENCES Department(Name)
);

CREATE TABLE Result


(
​ Student_ID INT,
Course_Code INT,
Marks FLOAT,
Grade VARCHAR(2),
PRIMARY KEY(Student_ID, Course_Code),
CONSTRAINT ref_studentid_by FOREIGN KEY(Student_ID) REFERENCES
Student(Student_ID),
CONSTRAINT ref_coursecode_by FOREIGN KEY(Course_Code) REFERENCES
Course(Course_Code)
);
2.INSERT INTO department
VALUES (1 , 'CSE' , 4 , '2005-01-12'),
​ (2 , 'LAW' , 3 , '2006-01-12'),
​ (3 , 'EEE' , 2 , '2004-01-12'),
​ (4 , 'BBA' , 4 , '2003-01-12');

INSERT INTO department


VALUES (1 , 'CSE' , 4 , '2005-01-12'),
​ (2 , 'LAW' , 3 , '2006-01-12');

Error Message:

INSERT INTO student


VALUES (222 , 'Arif' , 4.00 , 'CSE' , 'Cumilla'),
​ (218 , 'Junayed' , 3.21 , 'CSE' , 'Noakhali'),
​ (226 , 'Adil' , 4.20 , 'CSE' , 'Barishal'),
​ (255 , 'Sumi' , 4.00 , 'CSE' , 'India');

INSERT INTO student


VALUES (222 , 'Arif' , 4.00 , 'CSE' , 'Cumilla'),
​ (255 , 'Sumi' , 4.00 , 'CSE' , 'India');
Error Message:​

INSERT INTO course


VALUES (101 , 'MAT' , 3 , 'CSE'),
​ (111 , 'ETH' , 3 , 'EEE'),
​ (301 , 'ACT' , 3 , 'BBA'),
​ (102 , 'MAT' , 3 , 'LAW');

INSERT INTO course
VALUES (101 , 'MAT' , 3 , 'CSE'),
​ (102 , 'MAT' , 3 , 'LAW');
Error Message:​
INSERT INTO result
VALUES (222 , 101 , 55 , 'A'),
​ (218 , 102 , 60 , 'C'),
​ (226 , 101 , 80 , 'D'),
​ (255 , 111 , 99 , 'A');

INSERT INTO result


VALUES (222 , 101 , 55 , 'A'),
​ (255 , 111 , 99 , 'A');

Error Message:​

3. SELECT * FROM student

4. SELECT * FROM course

5. SELECT * FROM department

6. SELECT * FROM result

7. SELECT student_id, dept FROM student

8. SELECT course_code, dept FROM course

9. SELECT student_id, course_code, grade FROM result

10. SELECT name, building, estalish_year FROM department

You might also like