| 
                
Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | SillyJonStarting Member
 
 
                                        2 Posts | 
                                            
                                            |  Posted - 2013-10-26 : 00:44:01 
 |  
                                            | Hey guys, it's my first time using this website :)Here's my problem. I'm encountering this very weird problem,so I create a staff tableCREATE TABLE Staff (staffNo numeric(10),venueNo numeric(10),name nvarchar(20),DOB datetime,position nvarchar(20),salary numeric(8,2)CONSTRAINT staff_PK PRIMARY KEY(staffNo, venueNo),CONSTRAINT venue_FK FOREIGN KEY(venueNo) REFERENCES Venue);and thenwhen I create a professional therapist tableCREATE TABLE Professional_Therapist (staffNo numeric(10),specialization nvarchar(20),bonus numeric(8,2), CONSTRAINT professional_PK PRIMARY KEY(staffNo),CONSTRAINT staff_FK FOREIGN KEY(staffNo) REFERENCES Staff);it saysThe number of columns in the referencing column list for foreign key 'staff_fk' does not match those of the primary key in the referenced table 'Staff'. Looking forward to your replies :) |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-10-26 : 00:59:22 
 |  
                                          | the foreign key statements are not correct. It should specify the target column also CREATE TABLE Staff (staffNo numeric(10),venueNo numeric(10),name nvarchar(20),DOB datetime,position nvarchar(20),salary numeric(8,2)CONSTRAINT staff_PK PRIMARY KEY(staffNo, venueNo),CONSTRAINT venue_FK FOREIGN KEY(venueNo) REFERENCES Venue (venueNo));and thenwhen I create a professional therapist tableCREATE TABLE Professional_Therapist (staffNo numeric(10),specialization nvarchar(20),bonus numeric(8,2), CONSTRAINT professional_PK PRIMARY KEY(staffNo),CONSTRAINT staff_FK FOREIGN KEY(staffNo) REFERENCES Staff (staffNo));I'm assuming venueNo is column name in Venue table to which you want to set FK relationship to------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  |  
                                    | SillyJonStarting Member
 
 
                                    2 Posts | 
                                        
                                          |  Posted - 2013-10-26 : 01:24:10 
 |  
                                          | Thanks for your swift reply, but this did not fix the problem :( Just for note. I created the Staff first so I executed it. Then I created the professional therapist table then executed it and then I got the problem.Msg 1776, Level 16, State 0, Line 1There are no primary or candidate keys in the referenced table 'Staff' that match the referencing column list in the foreign key 'staff_FK'.Msg 1750, Level 16, State 0, Line 1Could not create constraint. See previous errors.So the problem is still there :( |  
                                          |  |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-10-26 : 04:43:11 
 |  
                                          | quote:nope this is differentDid you try creating StaffNo as a primary key in Staff table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsOriginally posted by SillyJon
 Thanks for your swift reply, but this did not fix the problem :( Just for note. I created the Staff first so I executed it. Then I created the professional therapist table then executed it and then I got the problem.Msg 1776, Level 16, State 0, Line 1There are no primary or candidate keys in the referenced table 'Staff' that match the referencing column list in the foreign key 'staff_FK'.Msg 1750, Level 16, State 0, Line 1Could not create constraint. See previous errors.So the problem is still there :(
 
 |  
                                          |  |  |  
                                |  |  |  |  |  |