[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

sql server constrainst issues while deleting

Asked by myselfrandhawa in SQL Server 2005, Databases Miscellaneous, SQL Server 2008

Tags: sql server 2005, databases, sql

I have three tables which joined in one and other fashion, that if i delete products, it should also delete its related values in the productoptions table and productoptionstable but due to some constrainst isue i am unable to do this:

i am getting this error:

Error! [Macromedia][SQLServer JDBC Driver][SQLServer]The DELETE statement conflicted with the REFERENCE constraint "productoptionitemsorderitemoptions". The conflict occurred in database "shopping", table "MyTets.OrderItemOptions", column 'OptionItemID'. Error Executing Database Query.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
Products Table: 
USE [shopping]
GO
/****** Object:  Table [MyTests].[Products]    Script Date: 11/07/2009 11:26:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [MyTests].[Products](
	[ProductID] [int] IDENTITY(1,1) NOT NULL,
	[Code] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Name] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ProdDescription] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Price] [decimal](18, 0) NULL CONSTRAINT [DF__Products__Price__38996AB5]  DEFAULT ((0)),
	[Cost] [decimal](18, 0) NULL CONSTRAINT [DF__Products__Cost__398D8EEE]  DEFAULT ((0)),
	[Net] [decimal](18, 0) NULL CONSTRAINT [DF__Products__Net__3A81B327]  DEFAULT ((0)),
	[ImageURL1] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ImageURL2] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[DateAvailable] [datetime] NULL CONSTRAINT [DF__Products__DateAv__3B75D760]  DEFAULT (getdate()),
	[StockQTY] [int] NULL CONSTRAINT [DF__Products__StockQ__3C69FB99]  DEFAULT ((0)),
	[CatID] [int] NULL CONSTRAINT [DF__Products__CatID__3D5E1FD2]  DEFAULT ((0)),
	[SubCatID] [int] NULL CONSTRAINT [DF__Products__SubCat__3E52440B]  DEFAULT ((0)),
	[Status] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[SortOrder] [int] NULL CONSTRAINT [DF__Products__SortOr__3F466844]  DEFAULT ((0)),
	[ShipCost] [decimal](18, 0) NULL CONSTRAINT [DF__Products__ShipCo__403A8C7D]  DEFAULT ((0)),
	[ShipCostMulti] [decimal](18, 0) NULL CONSTRAINT [DF__Products__ShipCo__412EB0B6]  DEFAULT ((0)),
	[Taxable] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK__Products__37A5467C] PRIMARY KEY CLUSTERED 
(
	[ProductID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] 
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [MyTests].[Products]  WITH CHECK ADD  CONSTRAINT [categoriesproducts] FOREIGN KEY([CatID])
REFERENCES [MyTests].[Categories] ([CatID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [MyTests].[Products] CHECK CONSTRAINT [categoriesproducts] 
 
PRODUCTOPTIONS TABLE: 
 
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [MyTests].[ProductOptions](
	[OptionID] [int] IDENTITY(1,1) NOT NULL,
	[ProductID] [int] NULL DEFAULT ((0)),
	[OptionName] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[Active] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[OptionID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] 
GO
ALTER TABLE [MyTests].[ProductOptions]  WITH CHECK ADD  CONSTRAINT [productsproductoptions] FOREIGN KEY([ProductID])
REFERENCES [MyTests].[Products] ([ProductID])
ON DELETE CASCADE
GO
ALTER TABLE [MyTests].[ProductOptions] CHECK CONSTRAINT [productsproductoptions] 

PRODUCTOPTIONSITEMS TABLE: 
 
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [MyTests].[ProductOptionItems](
	[OptionItemID] [int] IDENTITY(1,1) NOT NULL,
	[OptionID] [int] NULL DEFAULT ((0)),
	[OptionItemPrice] [money] NULL DEFAULT ((0)),
	[ItemDesc] [nvarchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
PRIMARY KEY CLUSTERED 
(
	[OptionItemID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] 
GO
ALTER TABLE [MyTests].[ProductOptionItems]  WITH CHECK ADD  CONSTRAINT [productoptionsproductoptionitems] FOREIGN KEY([OptionID])
REFERENCES [MyTests].[ProductOptions] ([OptionID])
ON DELETE CASCADE
GO
ALTER TABLE [MyTests].[ProductOptionItems] CHECK CONSTRAINT [productoptionsproductoptionitems]
[+][-]11/06/09 10:29 PM, ID: 25765199Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/09 01:55 AM, ID: 25765640Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 02:04 AM, ID: 25765668Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/09 02:08 AM, ID: 25765675Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/09 10:14 AM, ID: 25767337Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625