D
.docx
keyboard_arrow_up
School
Valencia College *
*We aren’t endorsed by this school
Course
4333C
Subject
Information Systems
Date
Feb 20, 2024
Type
docx
Pages
4
Uploaded by breezymehran
Name: Darren
Date: 2/5/2024
Constraints Assignment Submission Document
Code to create the Primary Keys (There should be 11 keys made - notice Crime_officers has two Primary Keys)
USE CityJailDatabase
ALTER TABLE aliases
ALTER COLUMN alias_id NUMERIC NOT NULL
GO
ALTER TABLE aliases
ADD PRIMARY KEY (alias_id);
USE CityJailDatabase
ALTER TABLE criminals
ALTER COLUMN criminal_id NUMERIC NOT NULL
GO
ALTER TABLE criminals
ADD PRIMARY KEY (criminal_id);
USE CityJailDatabase
ALTER TABLE crimes
ALTER COLUMN crime_id NUMERIC NOT NULL
GO
ALTER TABLE crimes
ADD PRIMARY KEY (crime_id);
USE CityJailDatabase
ALTER TABLE sentences
ALTER COLUMN sentence_id NUMERIC NOT NULL
GO
ALTER TABLE sentences
ADD PRIMARY KEY (sentence_id);
USE CityJailDatabase
ALTER TABLE prob_officers
ALTER COLUMN prob_id NUMERIC NOT NULL
GO
ALTER TABLE prob_officers
ADD PRIMARY KEY (prob_id);
USE CityJailDatabase
ALTER TABLE crime_charges
ALTER COLUMN charge_id NUMERIC NOT NULL
GO
ALTER TABLE crime_charges
ADD CONSTRAINT PK_crimeCharge PRIMARY KEY (charge_id) USE CityJailDatabase
ALTER TABLE crime_officers
ADD CONSTRAINT PK_crimeOfficer PRIMARY KEY (crime_id,officer_id);
USE CityJailDatabase
ALTER TABLE officers
ALTER COLUMN officer_id NUMERIC NOT NULL
GO
ALTER TABLE officers
ADD PRIMARY KEY (officer_id)
USE CityJailDatabase
ALTER TABLE appeals
ALTER COLUMN appeal_id NUMERIC NOT NULL
GO
ALTER TABLE appeals
ADD PRIMARY KEY (appeal_id);
USE CityJailDatabase
ALTER TABLE crime_codes
ALTER COLUMN crime_code NUMERIC NOT NULL
GO
ALTER TABLE crime_codes
ADD CONSTRAINT PK_crimeCode PRIMARY KEY (crime_code) Code to create the Foreign Keys (There should be 9 Foreign Keys made):
USE CityJailDatabase
ALTER TABLE aliases
ADD FOREIGN KEY (criminal_id) REFERENCES criminals(criminal_id);
GO
ALTER TABLE aliases
ALTER COLUMN criminal_id NUMERIC NOT NULL
;
USE CityJailDatabase
ALTER TABLE crime_officers
ADD CONSTRAINT FK_crimeId
FOREIGN KEY (crime_id) REFERENCES crimes(crime_id)
GO
ALTER TABLE crime_officers
ADD CONSTRAINT FK_officerId
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help