Question: This SQL script is not executing for some reason please help IF OBJECT_ID( 'TCourseStudents' ) IS NOT NULL DROP TABLE TCourseStudents IF OBJECT_ID( 'TCourses' )
This SQL script is not executing for some reason please help
IF OBJECT_ID( 'TCourseStudents' ) IS NOT NULL DROP TABLE TCourseStudents
IF OBJECT_ID( 'TCourses' ) IS NOT NULL DROP TABLE TCourses
IF OBJECT_ID( 'TStudents' ) IS NOT NULL DROP TABLE TStudents
IF OBJECT_ID( 'TGrades' ) IS NOT NULL DROP TABLE TGrades
IF OBJECT_ID( 'TCourseBooks' ) IS NOT NULL DROP TABLE TCourseBooks
IF OBJECT_ID( 'TBooks' ) IS NOT NULL DROP TABLE TBooks
IF OBJECT_ID( 'TRooms' ) IS NOT NULL DROP TABLE TRooms
IF OBJECT_ID( 'TInstructors' ) IS NOT NULL DROP TABLE TInstructors
----------------------------------------------------------------------------------------------------------
---- Problem 3
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
----Creating Table
----------------------------------------------------------------------------------------------------------
CREATE TABLE TCourses
(
intCourseID INTEGER NOT NULL
,intInstructorID INTEGER Not Null
,intRoomID INTEGER Not Null
,strCourse VARCHAR(50) NOT NULL
,strDescription VARCHAR(50) NOT NULL
,strMeetingTimes VARCHAR(50) NOT NULL
,CONSTRAINT TCourses_PK PRIMARY KEY( intCourseID )
)
CREATE TABLE TRooms ( intRoomID INTEGER Not Null
,strRoomNumber VARCHAR(50) NOT NULL
,intCapacity INTEGER NOT NULl
,CONSTRAINT TRooms_PK PRIMARY KEY (intRoomID)
)
CREATE TABLE TCourseStudents
(
intCourseStudentID INTEGER NOT NULL
,intCourseID INTEGER NOT NULL
,intStudentID INTEGER NOT NULL
,intGradeID INTEGER NOT NULL
,CONSTRAINT TCourseStudents_PK PRIMARY KEY( intCourseStudentID)
)
CREATE TABLE TStudents ( intStudentID INTEGER Not Null
,strStudentFirstName VARCHAR(50) NOT NULL
,strStudentLastName VARCHAR(50) NOT NULL
CONSTRAINT TStudents_Pk PRIMARY KEY (intStudentID)
)
CREATE TABLE TCourseBooks
(
intCourseBookID INTEGER NOT NULL
,intCourseID INTEGER NOT NULL
,intBookID INTEGER NOT NULL
CONSTRAINT TCourseBooks_PK PRIMARY KEY( intCourseBookID )
)
CREATE TABLE TBooks ( intBookID INTEGER NOT NULL
,strBookName VARCHAR(50) NOT NULL
,strAuthor VARCHAR(50) NOT NULL
,strISBN VARCHAR(50) NOT NULL
CONSTRAINT TBooks_Pk PRIMARY KEY (intBookID)
)
CREATE TABLE TInstructors
( intInstructorID INTEGER NOT NULL
,strFirstName VARCHAR(50) NOT NULL
,strLastName VARCHAR(50) NOT NULL
,CONSTRAINT TInstructors_Pk PRIMARY KEY(intInstructorID)
)
CREATE TABLE TGrades
( intGradeID INTEGER NOT NULL
,strGradeLetter VARCHAR(50) NOT NULL
,decGradePointValue VARCHAR(50) NOT NULL
CONSTRAINT TGrades_Pk PRIMARY KEY(intGradeID)
)
-- --------------------------------------------------------------------------------
-- 2.Creating Foreign key
-- --------------------------------------------------------------------------------
--
-- # Child Parent Column(s)
-- - ----- ------ ---------
-- 1 TCourses TRooms intRoomID
-- 2 TCourses TInstructors intInstructorID
-- 3 TCourseStudents TCourses intCourseID
-- 4 TCourseStudents TGrades intGradeID
-- 5 TCourseStudents TStudents intStudentID
-- 6 TCourseBooks TCourses intCourseID
-- 7 TCourseBooks TBooks intBookID
-- Alter Statatements
-- 1
ALTER TABLE TCourses ADD CONSTRAINT TCourses_TRooms_FK
FOREIGN KEY ( intRoomID ) REFERENCES TRooms ( intRoomID )
-- 2
ALTER TABLE TCourses ADD CONSTRAINT TCourses_TInstructors_FK
FOREIGN KEY ( intInstructorID ) REFERENCES TInstructors ( intInstructorID )
-- 3
ALTER TABLE TCourseStudents ADD CONSTRAINT TCourseStudents_TCourses_FK
FOREIGN KEY ( intCourseID ) REFERENCES TCourses ( intCourseID )
-- 4
ALTER TABLE TCourseStudents ADD CONSTRAINT TCourseStudents_TGrades_FK
FOREIGN KEY ( intGradeID ) REFERENCES TGrades ( intGradeID )
-- 5
ALTER TABLE TCourseStudents ADD CONSTRAINT TCourseStudents_TStudents_FK
FOREIGN KEY ( intStudentID ) REFERENCES TStudents ( intStudentID )
-- 6
ALTER TABLE TCourseBooks ADD CONSTRAINT TCourseBooks_TCourses_FK
FOREIGN KEY ( intCourseID ) REFERENCES TCourses ( intCourseID )
-- 7
ALTER TABLE TCourseBooks ADD CONSTRAINT TCourseStudents_TBooks_FK
FOREIGN KEY ( intBookID ) REFERENCES TBooks ( intBookID )
---------------------------------------------------------------------------------------------------------------------
--3 Adding Data to the Table
---------------------------------------------------------------------------------------------------------------------
INSERT INTO TInstructors(intInstructorID ,strFirstName ,strLastName)
VALUES (1,'Reena','Goel')
,(2,'Bob','Neild')
,(3,'Hamil','Robert')
,(4,'Raymond','Hermon')
INSERT INTO TRooms (intRoomID,strRoomNumber,intCapacity)
VALUES(1,'Main-101',30)
,(2,'Main-103',22)
,(3,'ATLC-407',20)
,(4,'ATLC-409',22)
INSERT INTO TCourses ( intCourseID,intInstructorID, intRoomID, strCourse, strDescription, strMeetingTimes)
VALUES (1,1,1, 'Math-126','Calculas', 'MWF 11:45 AM')
,(2,2,2, 'IT-101','HTML', 'MWF 12:45 PM')
,(3,3,3, 'SET-151','Programming', 'MWF 1:45 PM')
,(4,4,4, 'IT-111','Database', 'TF 11:45 AM')
,(5,5,5, 'IT-110','DotNet', 'MW 9:45 AM')
INSERT INTO TStudents(intStudentID,strStudentFirstName,strStudentLastName)
VALUES(1,'Hom','Dahal')
,(2,'Bishnu','Siwakoti')
,(3,'Huy','Damani')
,(4,'Harry','Tomaso')
INSERT INTO TGrades( intGradeID, strGradeLetter, decGradePointValue )
VALUES ( 1, 'A', 4.0 )
,( 2, 'B', 3.0 )
,( 3, 'C', 2.0 )
,( 4, 'D', 1.0 )
,( 5, 'F', 0.0 )
,( 6, 'S', 4.0 ) -- Satisfactory
,( 7, 'N', 0.0 ) -- Not Satisfactory
,( 8, 'I', 0.0 ) -- Incomplete
,( 9, 'W', 0.0 ) -- Withdrawal
INSERT INTO TCourseStudents(intCourseStudentID,intCourseID,intStudentID, intGradeID)
VALUES(1,1,1,1)
,(2,1,2,2)
,(3,2,3,3)
,(4,2,4,4)
INSERT INTO TBooks(intBookID,strBookName,strISBN)
VALUES (1,'Trigonometry and Calculas','0987987968')
,(2,'College level Calculas','0988775650')
,(3,'Starting with Visual Basic','9877553458')
,(4,'Visual Basic 2014','9875435469')
INSERT INTO TCourseBooks(intCourseBookID,intCourseID,intBookID)
VALUES (1,1,1)
,(2,1,2)
,(3,2,3)
,(4,2,4)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
