Skip to content

Instantly share code, notes, and snippets.

@FaronBracy
Created March 18, 2015 20:25
Show Gist options
  • Save FaronBracy/a2aabd485725165c677a to your computer and use it in GitHub Desktop.
Save FaronBracy/a2aabd485725165c677a to your computer and use it in GitHub Desktop.
Create a project version table
-- Create new table for keeping track of all the versions of project files
CREATE TABLE wa.ProjectVersion(
ProjectVersionId int IDENTITY(1,1) NOT NULL,
ProjectId int NOT NULL,
DateCreated datetime2(7) NOT NULL,
ProjectFileId varchar(50) NOT NULL
PRIMARY KEY CLUSTERED
(
ProjectVersionId ASC
)
)
-- Create a FK on ProjectId from ProjectVersion to the Project
ALTER TABLE wa.ProjectVersion
WITH CHECK ADD CONSTRAINT FK_ProjectVersion_Project_ProjectId FOREIGN KEY(ProjectId)
REFERENCES wa.Project(ProjectId)
-- Create a FK on LatestProjectVersionId from Project to the ProjectVersion
ALTER TABLE wa.Project
ADD LatestProjectVersionId int NOT NULL
ALTER TABLE wa.Project
WITH CHECK ADD CONSTRAINT FK_Project_LatestProjectVersionId_ProjectVersion_ProjectVersionId FOREIGN KEY(LatestProjectVersionId)
REFERENCES wa.ProjectVersion (ProjectVersionId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment