Skip to content

Instantly share code, notes, and snippets.

@gowtham758550
Last active August 9, 2022 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowtham758550/fc5555bfdbeebf4b6de90367457c92f7 to your computer and use it in GitHub Desktop.
Save gowtham758550/fc5555bfdbeebf4b6de90367457c92f7 to your computer and use it in GitHub Desktop.
--student table
CREATE TABLE [dbo].[Student] (
[StudentID] INT IDENTITY (1, 1) NOT NULL,
[LastName] NVARCHAR (50) NULL,
[FirstName] NVARCHAR (50) NULL,
[EnrollmentDate] DATETIME NULL,
PRIMARY KEY CLUSTERED ([StudentID] ASC)
)
--course table
CREATE TABLE [dbo].[Course] (
[CourseID] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (50) NULL,
[Credits] INT NULL,
PRIMARY KEY CLUSTERED ([CourseID] ASC)
)
--enrollment table
CREATE TABLE [dbo].[Enrollment] (
[EnrollmentID] INT IDENTITY (1, 1) NOT NULL,
[Grade] DECIMAL(3, 2) NULL,
[CourseID] INT NOT NULL,
[StudentID] INT NOT NULL,
PRIMARY KEY CLUSTERED ([EnrollmentID] ASC),
CONSTRAINT [FK_dbo.Enrollment_dbo.Course_CourseID] FOREIGN KEY ([CourseID])
REFERENCES [dbo].[Course] ([CourseID]) ON DELETE CASCADE,
CONSTRAINT [FK_dbo.Enrollment_dbo.Student_StudentID] FOREIGN KEY ([StudentID])
REFERENCES [dbo].[Student] ([StudentID]) ON DELETE CASCADE
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment