Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / July 2007

Tip: Looking for answers? Try searching our database.

FK Assignment on Surrogate Key Table Throws Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pbd22 - 31 Jul 2007 22:12 GMT
Hello.

I am getting the following error:

"""There are no primary or candidate keys in the referenced table
'UserPrecedence' that match the referencing column list in the foreign
key 'FK_USERS__UserPrecedence'."""

When running the following script:

alter table Users
add constraint FK_USERS__UserPrecedence
foreign key (userID)
references UserPrecedence(owner_userID)

I am just learning my way around Foreign Key assignments involving
surrogate keys. Do I need to be populating the owner_userID column in
UserPrecedence as I populate the userID column in Users? They are
supposed to be the same. I assumed that the PK/FK relationship causes
owner_userID to mimic userID in an automated way without much
intervention needed on my part. I guess I need some advice as to why I
am getting this error.

UserPrecedence Looks like this:

CREATE TABLE [dbo].[UserPrecedence](
    [up_order] [int] NOT NULL,
    [profile_userID] [bigint] NULL,
    [owner_userID] [bigint] NOT NULL,
    [search_name] [varchar](50) NULL,
CONSTRAINT [PK_UserPrecedence] PRIMARY KEY CLUSTERED
(
    [owner_userID] ASC,
    [up_order] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

And Users Looks Like This:

CREATE TABLE [dbo].[Users](
    [registerDate] [datetime] NULL,
    [password] [varchar](50) NULL,
    [role] [varchar](50) NULL,
    [securityQuestion] [varchar](50) NULL,
    [securityAnswer] [varchar](50) NULL,
    [zipCode] [varchar](50) NULL,
    [alternateEmail] [varchar](50) NULL,
    [emailAddress] [varchar](50) NULL,
    [bday_month] [varchar](50) NULL,
    [bday_day] [varchar](50) NULL,
    [bday_year] [varchar](50) NULL,
    [userID] [int] IDENTITY(1,1) NOT NULL,
    [gender] [varchar](50) NULL,
    [siteId] [varchar](50) NULL,
    [city] [varchar](50) NULL,
    [state] [varchar](50) NULL,
    [country] [varchar](50) NULL,
    [edit_date] [varchar](50) NULL,
    [lastName] [varchar](50) NULL,
    [firstName] [varchar](50) NULL,
    [confirmed] [bit] NULL DEFAULT ((0)),
CONSTRAINT [PK_userID] PRIMARY KEY CLUSTERED
(
    [userID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY
= OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
--CELKO-- - 31 Jul 2007 22:48 GMT
Have you considered a proper relational schema instead of a mock
sequential files?  Do you even know about ISO-11179 data element
naming rules?

Look at what you posted.  The name "UserPrecedence" is a relationship
among users, not an entity.  You are using camelCase which is soooo
bad even MS gave up on it.

>>  I am just learning my way around Foreign Key assignments involving surrogate keys. <<

Considering that FREIGN KEY is part of the foundation of RDBMS, isn't
that like a surgeon saying "I just found out about blood!" ?   Also,
SQL Server has no surrogate keys -- read Dr. Codd.  Why did you use
BIGINT?  Do you really have a data model bigger than all the atomic
particles in the Universe?

Please give me an example of a "zip_code VARCHAR (50)" please?  You
will get one because your design is so F***KED that it allows it.  In
fqct this piece of sh*t is full of  VARCHAR (50) columns.  You never
looked at a single ISO standard, have you?

Please stop[p programing before you kill someone.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.