USE master
GO
IF EXISTS (SELECT name FROM sys.sysdatabases
WHERE name = 'GrandfieldCollege')
DROP DATABASE GranfieldCollege
GO
CREATE DATABASE GrandfieldCollege
GO
USE GrandfieldCollege
GO
Use GrandfieldCollege
GO
CREATE TABLE License
(
LicenseKey int Primary Key Not Null,
LicenseType NVarChar Not Null,
LicenseStart Date Not Null,
LicenseTerm NVarChar Not Null,
LicenseEnd Date Not Null,
LicenseRegistrationKey nvarchar(50) Not Null,
)
GO
CREATE TABLE Software
(
SoftwareKey int Primary Key Not Null,
SoftwareName NVarChar Not Null,
SoftwareVersion NVarChar Not Null,
SoftwareManufacturer NVarChar Not Null,
SoftwareInstallType NVarChar Not Null,
SoftwareLicence NVarChar Not Null,
LicenseKey int Not Null,
CONSTRAINT fk_License FOREIGN KEY(LicenseKey)
REFERENCES License(LicenseKey),
)
GO
CREATE TABLE Install
(
InstallKey int Primary Key Not Null,
InstallDate datetime Not Null,
InstallMachine NVarChar Not Null,
InstallSoftware NVarChar Not Null,
InstallSuccesful NVarChar Not Null,
SoftwareKey int Not Null,
CONSTRAINT fk_Software FOREIGN KEY(SoftwareKey)
REFERENCES Software (SoftwareKey),
)
GO
CREATE TABLE Location
(
LocationKey Nvarchar Not Null Primary Key,
BuildingName nvarchar(50) Not Null,
BuildingRoom Nvarchar (50) Not Null,
)
GO
CREATE TABLE Machine
(
MachineCSS int Primary Key Not Null,
MachineInstalledPrograms NvarChar Not Null,
MachineInstallDate NvarChar Not Null,
MachineConfiguration NvarChar Not Null,
LocationKey NvarChar Not Null,
InstallKey NvarChar Not Null,
CONSTRAINT fk_Location FOREIGN KEY(LocationKey)
REFERENCES Location(LocationKey),
CONSTRAINT fk_Install FOREIGN KEY(InstallKey)
REFERENCES Install(InstallKey)
)
GO
CREATE TABLE [User]
(
UserID NVarChar(64) Primary Key Not Null,
UserFirstName NVarChar Not Null,
UserLastName NVarChar Not Null,
)
GO
CREATE TABLE UserMachine
(
UserMachineID int Primary Key Not Null,
MachineCSS int Not Null,
UserID NVarChar(64) Not Null,
CONSTRAINT fk_Machine FOREIGN KEY(MachineCSS)
REFERENCES Machine(MachineCSS),
CONSTRAINT fk_User FOREIGN KEY(UserID)
REFERENCES [User](UserID)
)
GO
CREATE TABLE [Request]
(
RequestID int Primary Key Not Null,
RequesterFirst NVarChar Not Null,
RequesterLast NVarChar Not Null,
RequestDate Date Not Null,
RequestSoftware NVarChar Not Null,
RequestReason NVarChar Not Null,
RequestStatus NVarChar Not Null,
)
GO
CREATE TABLE RequestSoftwareUser
(
UserRequestID NVarChar Not Null Primary Key,
UserID NVarChar(64) Not Null,
RequestID int Not Null,
CONSTRAINT fk_UserID FOREIGN KEY (UserID)
REFERENCES [User](UserID),
CONSTRAINT fk_RequestID FOREIGN KEY (RequestID)
REFERENCES Request(RequestID),
)