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:
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);