Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2010, 11:41 AM
Registered User
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Foreign Key in SQLServer 2000?

While trying to create foreign key on a table in SQLServer2000 following error is coming

"The columns in "tbl_faculty" do not match an existing primary key or UNIQUE constraint"

I work in MySQL and SQLServer 2000 is new to me.

Any kind help will be appreciated.Thanks in advance.
 
Old March 9th, 2010, 05:40 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You would get the same error in MySQL. (Well, same kind of error.)

It just means that you are trying to create a foreign key but the table and field(s) you are linking *TO* are not guaranteed to be unique.

Example:
Code:
tbl_faculty
name :: dept
Adams :: Engineering
Adams :: History
 
other_table
name FOREIGN KEY to tbl_faculty(name)
But you can't *use* tbl_faculty(name) as a foreign key because there are more than one record with the same value for "name" in tbl_faculty.

NOTE: And even if there are no duplicates at the time you create the foreign key, it will be rejected because there *may be* duplicates created later.

A foreign key *must* link to a field (or set of fields) that is guaranteed to have unique values. Meaning that the field(s) must be the primary key of the other table or must be a indexed as UNIQUE. Same as with MySQL.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key not updating with Primary key xavier1945 BOOK: Access 2003 VBA Programmer's Reference 2 July 4th, 2007 09:48 PM
Composite Foreign Key bijgupt SQL Server 2005 6 May 4th, 2007 08:46 AM
SQLserver 2000 vs SQLserver 2005 Express cJeffreywang BOOK: Beginning ASP.NET 2.0 and Databases 0 April 22nd, 2007 09:52 AM
FOREIGN KEY and PRIMARY KEY Constraints junemo Oracle 10 June 15th, 2004 01:00 AM
Foreign Key Problem re_anu SQL Server 2000 1 September 26th, 2003 10:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.