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 ShekhawatPosted Jun 1, 2013, 1:33 PM
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,
)
Bineesh ViswanathPosted Jun 5, 2013, 1:42 AM
Sandeep Singh ShekhawatPosted Jun 1, 2013, 6:33 AM
http://www.c-sharpcorner.com/Forums/Thread/212239/call-multiple-foreign-key-in-a-table.aspx