Sir, I am now on SQL Query .
I have a bit error in following Query.
ALTER PROCEDURE markCreate2
AS
CREATE TABLE tbl_Mark2
(
markId int primary key,
studentId int foreign key references tbl_Student1(studentId),
subjectId int foreign key references tbl_Subject(subjectId),
examId int foreign key references tbl_Exam(examId),
Mark int,
passMark int,
maxMark int,
)
it saved, but getting a message: - Could not create constraint. See previous errors.
No rows affected.
(0 row(s) returned)
@RETURN_VALUE =
Finished running [dbo].[markCreate2].
please correct this query.
Loading


Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Jun 1, 2013, 9:33 AM EDT
Hi Bineesh,
You have all these three tables already in database. If you don't have these tables in database then you will get error like
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
So first create child/subtables then create parent/base table in data base then you will not get error. Your query for create table is Okay but should be execute like
CREATE TABLE tbl_Student1
(
studentId int primary key
)
CREATE TABLE tbl_Subject
(
subjectId int primary key
)
CREATE TABLE tbl_Exam
(
examId int primary key
)
CREATE TABLE tbl_Mark2
(
markId int primary key,
studentId int foreign key references tbl_Student1(studentId),
subjectId int foreign key references tbl_Subject(subjectId),
examId int foreign key references tbl_Exam(examId),
Mark int,
passMark int,
maxMark int,
)
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted Jun 1, 2013, 2:33 AM EDT
http://www.c-sharpcorner.com/Forums/Thread/212239/call-multiple-foreign-key-in-a-table.aspx
Bineesh ViswanathRank #1,681 · 907 reputationPosted Jun 4, 2013, 9:42 PM EDT