How do I create a foreign key in SQL Server? -
i have never "hand-coded" object creation code sql server , foreign key decleration seemingly different between sql server , postgres. here sql far:
drop table exams; drop table question_bank; drop table anwser_bank; create table exams ( exam_id uniqueidentifier primary key, exam_name varchar(50), ); create table question_bank ( question_id uniqueidentifier primary key, question_exam_id uniqueidentifier not null, question_text varchar(1024) not null, question_point_value decimal, constraint question_exam_id foreign key references exams(exam_id) ); create table anwser_bank ( anwser_id uniqueidentifier primary key, anwser_question_id uniqueidentifier, anwser_text varchar(1024), anwser_is_correct bit );
when run query error:
msg 8139, level 16, state 0, line 9 number of referencing columns in foreign key differs number of referenced columns, table 'question_bank'.
can spot error?
create table question_bank ( question_id uniqueidentifier primary key, question_exam_id uniqueidentifier not null, question_text varchar(1024) not null, question_point_value decimal, constraint fk_questionbank_exams foreign key (question_exam_id) references exams (exam_id) );
Comments
Post a Comment