Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Mr. Ravi has just created a table named “Student” containing columns Sname, Class and Marks. 

After creating the table, he realized that he has forgotten to add a foreign key column RollNo that references another table named “Enroll”. Help him in writing an SQL command to add a foreign key column RollNo of integer type to the table Student.

Thereafter, write the command to insert the following record in the table:

RollNo- 101

Sname- Raj

Class: XII

Marks: 85

Answer:

Answer by student

SQL command to add a foreign key column RollNo of integer type to the table Student is:

ALTER TABLE Student ADD RollNo integer CONSTRAINT fk_Student_Enroll FOREIGN KEY (RollNo) REFERENCES Enroll (RollNo);

The SQL command to insert the record in the table is:

INSERT INTO Student (RollNo, Sname, Class, Marks) VALUES (101, 'Raj', 'XII', 85);

Detailed answer by teachoo

The rest of the post is locked. Join Teachoo Black to see the full post.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.