0% found this document useful (0 votes)
94 views5 pages

Create Table Customer

The document contains SQL statements to create tables for customers, products, customer-product relationships, patients, hospitals, appointments, and others. It also contains statements to insert, update, delete, and select data from the tables. Primary keys and foreign keys are defined to link the tables together in relationships.
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)
94 views5 pages

Create Table Customer

The document contains SQL statements to create tables for customers, products, customer-product relationships, patients, hospitals, appointments, and others. It also contains statements to insert, update, delete, and select data from the tables. Primary keys and foreign keys are defined to link the tables together in relationships.
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/ 5

Create table Customer

CustomerID varchar(20) not null,

CustomerName varchar(20),

Primary Key(CustomerID)

};

Create table Product

Product varchar(20) not null,

Price decimal,

Primary Key(Product)

};

Create table CustomerProduct

CustomerID int not null,

PRoductID int not null,

Foreign Key(CustomerID) references Customer(CustomerID),

Foreign Key(Product) references Customer(Product),

Primary Key(CustomerID,Product)

};

Update Poduct

Set Product=’Plant Control’

Where Product=’Weed Killer’

Select RentalStartDate,RentalEndDate

From Rental

Where RenatlEndDate=’30/01/2015’
Alter
Alter table Customer
Add age int

Drop
Create table Customer
{
CustomerID varchar(30) not null,
CustomerName varchar(30).
Primary Key (CustomerID)
};

Alter table Customer


Add Age int
Alter table Customer
Add Email v
Insert into Customer(CustomerID,CustomerName,Age,Email)
Values()

Transaction/Relation T1 T2 T3 T4 T5 T6
Film C C R R U
Rent C R R
Customer D R

Transaction/Relation T1 T2 T3 T4 T5 T6
Member D U R
Class_Booking C R
Class C U R

Create table Patient


{
PatientID int not null,
Title varchar(30),
`FirstName varchar(30),
Surname varchar(30),
Email varchar(30),
Primary Key(PatientID)
};
Create table Hospital
{
HospitalID int not null,
HospitalName varchar(30),
City varchar(30),
Primary Key(HospitalID)
};
Create table Appointment
{
AppointmentID int not null,
PatientID int,
HospitalID int ,
Date Date,
StartTime Time,
Length int,
Primary Key(AppointmentID)
Foreign Key(PatientID) refereneces Patient(PatientID)
Foreign Key(HospitalID) references Hospital (HospitalID)
};

Delete
From Patient
Where FirstName=’Gemma’
AND LastName=’Jones’
Select *
From tblCustomer
Order By Town
Select
tblCustomer
Order BY DateOFBirth

Select FirstName,Surname,NoofAssessments
From Student s,Module m, AssessmentResult ar
Where s.StudentID=ar.StudentID
AND m.ModuleID=ar.ModuleID

Select EmployeeID,Surname,Department
From tblEmployee
Where Department=’Grocery’

Select SupermarketID,SupermarketName,Town
Form tblSupermarket
Where Employee>=35

Select e.EmployeeID,e.FirstName,e.Surname,s.SupermarketName
From tblEmployee e,tblSupermarket s,tblEmployeeSupermarket es
Where e.EmployeeID=es.EmployeeID
AND s.SupermarketID=es.Supermarket
AND e.Department=’Grocery’

Select*
From tblSalesRep
Order By DESC

Select s.RepID,s.FirstName,s.Surname,c.ContactName,c.Town
From tblSalesRep s,tblCompany c,tblRepCompany rc
Where s.RepID=rc.RepID
AND c.CompanyID=rc.CompanyID
AND c.No_of_Employees>=100
Select CompanyID,CompanyName,Town
From tblCompany
Where Town=’Nelson’

Select *
From tblStudent
Order By School

Select s.StudentID,s.FirstName,s.Surname
From tblStudent s,tblModule m,tblStudentModule sm
Where s.StudentID=sm.StudentID
AND m.ModuleID=sm.ModuleID
AND m.ModuleCode=1
Order By School DESC

Select s.StudentID,s.FirstName,s.Surname
From tblStudent,tblmodule
Where s.StudentID=sm.StudentID
AND m.ModuleID=sm.ModuleID
AND m.Title=’Systems Analysis’

You might also like