Item #1: Develop scripts to INSERT data into Instructor, and Student tables. Loa
ID: 3787460 • Letter: I
Question
Item #1:
Develop scripts to INSERT data into Instructor, and Student tables. Load the tables with sample data with at least 10 rows.
Instructor
Name
Data Type
Constraint
Address
Nvarchar (100)
Not Null
InstructorID
Int
Primary Key
Phone Number
Nvarchar(10)
Not null
Office
Int
Not null
Office Hours
Nvarchar (30)
Not null
Department
Nvarchar (15)
Not null
Department ID
Int
Not null
First Name
Nvarchar (30)
Not null
Last Name
Nvarchar (30)
Not null
Student
Name
Data Type
Constraint
Address
Nvarchar (100
Not Null
StudentID
Int
Primary Key
Phone Number
Nvarchar(10)
Not null
Major
Char (10)
Not null
GPA
Decimal (3,2)
Not null
First Name
Nvarchar (30)
Not null
Last Name
Nvarchar (30)
Not null
I tried to entering data into the table for “Instructor” using the following information:
INSERT INTO Instructor(Address,InstructorID, [Phone Number], Office, [Office Hours], Department, [Department ID], [First Name], [Last Name])
VALUES ('240 Campus St','301008','808-555-1234', 'A123', '0800 - 1300', 'History', 'HIS', 'Steve', 'McGarrett');
And received the following error message:
Msg 8152, Level 16, State 4, Line 1
String or binary data would be truncated.
The statement has been terminated.
Name
Data Type
Constraint
Address
Nvarchar (100)
Not Null
InstructorID
Int
Primary Key
Phone Number
Nvarchar(10)
Not null
Office
Int
Not null
Office Hours
Nvarchar (30)
Not null
Department
Nvarchar (15)
Not null
Department ID
Int
Not null
First Name
Nvarchar (30)
Not null
Last Name
Nvarchar (30)
Not null
Explanation / Answer
while inserting data into table with a column data type as NVARCHAR we should use the prefix N in insert query before the data which has to be inserted,which is shown below
the following are the 10 queries (script) which will insert data into the instructor table.
===================================================================================
INSERT INTO INSTRUCTOR VALUES (N'240 Campus St1', '10',N'8085551234', '123',N '08:00 – 15:00', N 'History', '1', N'Steve',N 'McGarrett');
INSERT INTO INSTRUCTOR VALUES (N'241 Campus St2', '11',N'8085512345', '124',N '09:00 – 16:00', N 'Chemistry', '2', N'Alia',N 'July');
INSERT INTO INSTRUCTOR VALUES (N'242 Campus St3', '12',N'8085567980', '125',N '08:00 – 15:00', N 'Physics', '3', N'Mega',N 'Sahan');
INSERT INTO INSTRUCTOR VALUES (N'243 Campus St4', '13',N'8081102034', '126',N '10:00 – 17:00', N 'Maths', '4', N'Gana',N 'Glory');
INSERT INTO INSTRUCTOR VALUES (N'244 Campus St5', '14',N'8055252234', '127',N '08:00 – 15:00', N 'Civics', '5', N'Arjun',N 'Happy');
INSERT INTO INSTRUCTOR VALUES (N'245 Campus St6', '15',N'8055555234', '128',N '10:00 – 13:00', N 'English', '6', N'Gana',N 'Sam');
INSERT INTO INSTRUCTOR VALUES (N'246 Campus St7', '16',N'8085555552', '129',N '08:00 – 13:00', N 'History', '1', N'Hari',N 'sasa');
INSERT INTO INSTRUCTOR VALUES (N'247 Campus St8', '17',N'8085551630', '130',N '08:00 – 20:00', N 'Chemistry', '2', N'Samba',N 'Mona');
INSERT INTO INSTRUCTOR VALUES (N'248 Campus St9', '18',N'8085551442', '131',N '07:00 – 16:00', N 'Physics', '3', N'Gane',N 'Suri');
INSERT INTO INSTRUCTOR VALUES (N'249 Campus St10', '19',N'8085558895', '132',N '09:00 – 14:00', N 'Maths', '4', N'Virat',N 'Kohli');
===================================================================================
The following is the script for the student table insertion here i provided 10 sample insert queries script:
INSERT INTO STUDENT VALUES (N'Street-1','10',N'8085551234', 'A123', '6.2',N'SAI',N'KUMAR');
INSERT INTO STUDENT VALUES (N'Street-2','11',N'9966336652', 'A124', '7.2',N'SONA',N'GIRI');
INSERT INTO STUDENT VALUES (N'Street-3','12',N'9955951234', 'A125', '8.5',N'SAI',N'HSRI');
INSERT INTO STUDENT VALUES (N'Street-4','13',N'8055220234', 'A126', '9.2',N'SARIK',N'SUK');
INSERT INTO STUDENT VALUES (N'Street-5','14',N'8080023234', 'A127', '5.2',N'SONITA',N'GNAN');
INSERT INTO STUDENT VALUES (N'Street-6','15',N'8085532234', 'A128', '8.6',N'KOTE',N'KUMAR');
INSERT INTO STUDENT VALUES (N'Street-7','16',N'8066662234', 'A129', '5.2',N'FIJI',N'SURI');
INSERT INTO STUDENT VALUES (N'Street-8','17',N'8082201234', 'A130', '3.5',N'SAI',N'KUMAR');
INSERT INTO STUDENT VALUES (N'Street-9','18',N'8232321234', 'A131', '6.8',N'SAJJ',N'RRR');
INSERT INTO STUDENT VALUES (N'Street-10','19',N'8080051234', 'A132', '6.9',N'SAI',N'KUMAR');
here in this student table we need to enter the same data in the student id column which is used in instructor id column in instructor table because it is used primary key in declaration.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.