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.