0% found this document useful (0 votes)
13 views7 pages

Q1 Dbi202

The document contains the SQL code to create multiple tables to model different entities and relationships for various database schemas including: a vehicle rental system with branches, vehicles, customers and rent records; an employee system with departments, offices, employees and work history; a classroom attendance system with teachers, classes, students and attendance records; a staff reporting system; and an employee and dependents system. Primary and foreign keys are defined to link the tables together.
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)
13 views7 pages

Q1 Dbi202

The document contains the SQL code to create multiple tables to model different entities and relationships for various database schemas including: a vehicle rental system with branches, vehicles, customers and rent records; an employee system with departments, offices, employees and work history; a classroom attendance system with teachers, classes, students and attendance records; a staff reporting system; and an employee and dependents system. Primary and foreign keys are defined to link the tables together.
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/ 7

CREATE TABLE Branches(

BranchID int PRIMARY KEY,


Name nvarchar(100),
Address nvarchar(200),
)

CREATE TABLE Vehicles(


VehicleID int PRIMARY KEY,
Model nvarchar(50),
Maker varchar(20),
Year int,
RentalPrice float,
)

CREATE TABLE Customers(


CustomerID int PRIMARY KEY,
FullName nvarchar(100),
Address nvarchar(200),
)

CREATE TABLE Rent(


PickupDate date,
DropoffDate date,
BranchID int FOREIGN KEY REFERENCES Branches(BranchID),
VehicleID int FOREIGN KEY REFERENCES Vehicles(VehicleID),
CustomerID int FOREIGN KEY REFERENCES Customers(CustomerID),
PRIMARY KEY(BranchID, CustomerID, VehicleID, PickupDate)
)
CREATE TABLE Departments(
DeptID VARCHAR(15) PRIMARY KEY,
Name NVARCHAR(60)
)

CREATE TABLE Offices(


OfficeNumber INT PRIMARY KEY,
Address NVARCHAR(30),
Phone NVARCHAR(15),
DeptID VARCHAR(15) FOREIGN KEY REFERENCES Departments(DeptID)
)

CREATE TABLE Employees(


EmployeeID INT PRIMARY KEY,
FullName NVARCHAR(50),
OfficeNumber INT FOREIGN KEY REFERENCES Offices(OfficeNumber)
)

CREATE TABLE WorkFor(


[From] Date,
Salary float,
[To] Date,
EmployeeID INT FOREIGN KEY REFERENCES Employees(EmployeeID),
DeptID VARCHAR(15) FOREIGN KEY REFERENCES Departments(DeptID),
PRIMARY KEY(EmployeeID,DeptID,[From])
)
1.create table Teachers(
TeacherID int primary key,
Name nvarchar(50),
Address nvarchar(200),
Gender char(1)
)

create table Classes(


ClassID int Primary Key,
GroupID char(6),
coueseID char(6),
NoCredits int,
Semester char(10),
year int,
TeacherID int
constraint fk_Classes_Teachers FOREIGN KEY(TeacherID) references
Teachers(TeacherID)
)

create table Students(


StudentID int Primary Key,
Name nvarchar(50),
Address nvarchar(200),
Gender char(1),
)

create table Attend(


Date date,
Slot int,
Attend bit,
StudentID int,
ClassID int,
primary key(Date, Slot, StudentID, ClassID),
constraint fk_Attend_Students FOREIGN KEY(StudentID) references
Students(StudentID),
constraint fk_Attend_Classes FOREIGN KEY(ClassID) references
Classes(ClassID)
)
CREATE TABLE Staffs(
StaffID int PRIMARY KEY,
Name nvarchar(100),
)

CREATE TABLE Logins(


username nvarchar(50) PRIMARY KEY,
[Password] nvarchar(255),
[Role] nvarchar(100),
StaffID int FOREIGN KEY REFERENCES Staffs(StaffID)
)

CREATE TABLE Reports(


ReportNumber int PRIMARY KEY,
[Date] date,
IssueReturn nvarchar(200),
username nvarchar(50) FOREIGN KEY REFERENCES Logins(username),
)
CREATE TABLE Departments(
DeptID varchar(20) PRIMARY KEY,
name nvarchar(200),
office nvarchar(100)
)
CREATE TABLE Employees(
EmpCode nvarchar(20) PRIMARY KEY,
Name nvarchar(50),
BirthDate Date,
DeptID varchar(20) Foreign key references Departments(DeptID)
)
CREATE TABLE Dependant(
Number int ,
Name nvarchar(50),
BirthDate Date,
Role nvarchar(30),
EmpCode nvarchar(50) foreign key references Employees(EmpCode),
PRIMARY KEY(Number,EmpCode)
)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy