PDA

View Full Version : خطا در ایجاد Relation بین جداول



hooty70
دوشنبه 11 شهریور 1392, 11:48 صبح
سلام من دوتا جدول دارم که فیلداشون بصورت زیره:

patientTBL
ID=> primary Key
Case ID => int => primary key
(Fname,Lname,age,birthdate, fullname=>nvarchar(max

testTBl
Test_ID=>int primary key
Test_Code=>nvarchar50
score
testdate
teststarttime
patient_ID
Fullname

بین اینا که می خوام Relation ایجاد کنم بین Case_ID و Patient _ID این خطارو میده موقع save چکار کنم



/*
Monday, September 02, 201311:11:25 AM
User:
Server: (local)
Database: GeneralDatabase
Application:
*/

'TestsTBL' table saved successfully
'PatientsTBL' table
- Unable to create relationship 'FK_PatientsTBL_TestsTBL'.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_PatientsTBL_TestsTBL". The conflict occurred in database "GeneralDatabase", table "dbo.TestsTBL", column 'Test_ID'.

ممنون میشم کمکم کنید

sajadsobh
دوشنبه 11 شهریور 1392, 17:50 عصر
میشه بگی ارتباط رو چطور میخوای برقرار کنی؟! بین کدوم فیلدها؟

بهزاد علی محمدزاده
دوشنبه 11 شهریور 1392, 19:41 عصر
سلام . در جدول patientTBL شما composite primary key دارید . اما در جدول testTBl به یکی از کلید ها فقط ارجاع دادین و این جامعیت دیتابیس و نقض می کنه چون کلید ترکیبی دارید . امتحان کن و به هردوش رفرنس بده .

hooty70
دوشنبه 11 شهریور 1392, 19:42 عصر
سلام میخوام Case_ID رو به Patient_ID وصل کنم

بهزاد علی محمدزاده
دوشنبه 11 شهریور 1392, 19:54 عصر
این دو تا با هم کلید ترکیبی هستند :
ID=> primary Key
Case ID => int => primary key

کلید خارجی به یکی از اینها نمی تونه رفرنس بده . بلکه اون هم باید ترکیبی باشه


testTBl
Test_ID=>int primary key
Test_Code=>nvarchar50
score
testdate
teststarttime
patient_ID
ID
Fullname