0% found this document useful (0 votes)
69 views4 pages

Majors (Majorid, Majorname) Students (Studentid, Firstname, Lastname, Age, Majorid)

The document describes the design and implementation of a student management database. It includes the creation of two tables (Majors and Students) with attributes to store major and student information, the insertion of sample data, and SQL queries to retrieve and analyze data from the tables. Sample data is inserted into the Majors and Students tables. Queries are written to display student information by major, count students by major, and only show majors with more than 3 students.

Uploaded by

tuan anh
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)
69 views4 pages

Majors (Majorid, Majorname) Students (Studentid, Firstname, Lastname, Age, Majorid)

The document describes the design and implementation of a student management database. It includes the creation of two tables (Majors and Students) with attributes to store major and student information, the insertion of sample data, and SQL queries to retrieve and analyze data from the tables. Sample data is inserted into the Majors and Students tables. Queries are written to display student information by major, count students by major, and only show majors with more than 3 students.

Uploaded by

tuan anh
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/ 4

Student management database has relations as following:

Majors(majorID, majorName)

Students(studentID, firstName, lastName, age, majorID)

Now students have to complete all following tasks:

1/ Logical database design: use Draw.io tool to create ERD (Entity relationship
diagram).

2/ Physical database design: Detailed description of each table in the database

Table: Majors

Column name
Data type Allow nulls Description
(Field name)
mID nchar(10) PK
mName varchar(50) Fk

Table: Students: studentID, FirstName, LastName, Age, majorID

Column name
Data type Allow nulls Description
(Field name)
studentID nchar(10) PK
FirstName nvarchar(100) FK
LastName nvarchar(100) FK
Age int FK
majorID nchar FK

3/ Create Databse called “StudentDB1” and all its tables by SQL


Create database StudentDB1;

use StudentDB1;

create table Majors(


majorID nchar (10) primary key not null,
majorName nvarchar (100) not null,
);

create table Students(


studentID nchar (10) not null,
firstName nvarchar (100),
lastName nvarchar (100) not null,
age int not null,
majorID nchar (10) foreign key references Majors(majorID),
);

4/ Database diagram:

5/ Add data into the table “Majors”


insert into Majors(majorID,majorName)
values('BA','Business Administration');
insert into Majors(majorID,majorName)
values('EN','English');
insert into Majors(majorID,majorName)
values('FR','French');
insert into Majors(majorID,majorName)
values('IT','Information Technology');
insert into Majors(majorID,majorName)
values('MA','Math');

6/ Add data into the table “Students”

insert into Students(studentID, FirstName, LastName, Age, majorID)


values ('01', 'Nguyen Thao', 'Van', 20, 'IT');
insert into Students(studentID, FirstName, LastName, Age, majorID)
values ('02', 'Tran Minh', 'Hung', 21, 'IT');
insert into Students(studentID, FirstName, LastName, Age, majorID)
values ('03', 'Le Van', 'Teo', 30, 'IT');
insert into Students(studentID, FirstName, LastName, Age, majorID)
values ('04', 'Tran Bao', 'Minh', 20, 'BA');
insert into Students(studentID, FirstName, LastName, Age, majorID)
values ('05', 'Nguyen Tuyet', 'Lan', 19, 'BA');
insert into Students(studentID, FirstName, LastName, Age, majorID)
values ('06', 'Tran Thi', 'Ngoc', 20, 'BA');
insert into Students(studentID, FirstName, LastName, Age, majorID)
values ('07', 'Nguyen Tuyet', 'Hong', 22, 'BA');

7/ Display all students as follwoing table:

fileds are collected from 2 tables: Students and Majos

select S.studentID,S.FirstName,S.LastName,S.Age,M.majorName
from Students S, Majors M
where S.majorID = M.majorID;

8/ Display all students of Information technology major as follwoing table:

select S.studentID,S.FirstName,S.LastName,S.Age,M.majorName
from Students S, Majors M
where S.majorID = M.majorID and S.majorID = 'IT'

9/ Count all students of each major as follwoing table:

select M.majorName, COUNT(S.majorID) as


Quancity
from Students S, Majors M
where S.majorID = M.majorID
group by M.majorName

10/ Same as question 9 but only show majors with Quantity > 3
select M.majorName, count(S.studentID) as Quantity
from Students S, Majors M
where S.majorID = M.majorID
group by M.majorName
having count(S.studentID) > 3;

File name: Lab2@Trịnh Lê Huy – huytlgcs200572

Submit this file on CMS

You might also like