I have a web app w/a form that takes user data and inserts into a customers
table. Now if I try to insert a record w/identical 'customerName', this is
the error:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_transactions_customers'. The conflict occurred in database 'CHZ', table
'customers', column 'CID'.
Now the constraint 'FK_transactions_customers' uses CID.Customers as my
Primary key and Trans.CID as the foreign key. I can't seem to figure out wh
y
the error is thrown when using an existing 'customerName'.
Here's the ddl:
CREATE TABLE [customers] (
[CID] [int] IDENTITY (1, 1) NOT NULL ,
[customerName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[customerID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[address] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[city] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[state] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[zip] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[phone] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CDB] [bit] NULL ,
CONSTRAINT [PK_customers] PRIMARY KEY NONCLUSTERED
(
[CID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
TIA for help.Post the DDL for Trans, as well as the offending INSERT statement.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"Eric" <Eric@.discussions.microsoft.com> wrote in message
news:FB917852-FA0D-4EE8-B6DD-15A142D3B934@.microsoft.com...
I have a web app w/a form that takes user data and inserts into a customers
table. Now if I try to insert a record w/identical 'customerName', this is
the error:
INSERT statement conflicted with COLUMN FOREIGN KEY constraint
'FK_transactions_customers'. The conflict occurred in database 'CHZ', table
'customers', column 'CID'.
Now the constraint 'FK_transactions_customers' uses CID.Customers as my
Primary key and Trans.CID as the foreign key. I can't seem to figure out
why
the error is thrown when using an existing 'customerName'.
Here's the ddl:
CREATE TABLE [customers] (
[CID] [int] IDENTITY (1, 1) NOT NULL ,
[customerName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[customerID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[address] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[city] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[state] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[zip] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[phone] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CDB] [bit] NULL ,
CONSTRAINT [PK_customers] PRIMARY KEY NONCLUSTERED
(
[CID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
TIA for help.|||You are trying to insert a customer which isn=B4t present in the
transaction table. Check this.
HTH, jens Suessmeyer.|||"Jens" wrote:
> You are trying to insert a customer which isn′t present in the
> transaction table. Check this.
> HTH, jens Suessmeyer.
>
Shouldn't be a problem, unless the foreign key constraint is backwards
(customers references transactions instead of transactions references
customers).
Showing posts with label identical. Show all posts
Showing posts with label identical. Show all posts
Subscribe to:
Posts (Atom)