Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
CREATE TABLE [dbo].[tbl_AddItems](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[ProductId]  AS ('SHPLT'+right('0000'+CONVERT([varchar](10),[ID],(0)),(4)))PERSISTED NOT NULL,
	CONSTRAINT PK_ProductId PRIMARY KEY CLUSTERED(ProductId),
	[ProductCategory] [varchar](20) NULL,
	[ProductName] [varchar](30) NULL,
	[Price] [decimal](6, 2) NULL,
	[ProductCode] [varchar](20) NULL,
	[Descriptions] [varchar](max) NULL,
	[Stock] [int] NULL,
	[Discount] [int] NULL
)


SQL
CREATE TABLE [dbo].[tbl_AddImages]
(
	[Id] INT IDENTITY(1,1) NOT NULL,
	[ProductId] VARCHAR(10) NOT NULL,
	[ImgId] [varchar](20) NULL,
	[ImgPath] [varchar](100) NULL
	
 CONSTRAINT [FK_ProductId] FOREIGN KEY([ProductId]) REFERENCES [tbl_AddItems] ([ProductId])
)



Here i want to set primary key and foreign key on my tables tbl_AddItems,tbl_AddImages
now i'm getting an error at tbl_AddImages Creation


"CREATE TABLE failed because the following SET options have incorrect settings: 'ANSI_PADDING'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations."


Anyone please help me regarding this?
Posted
Comments
Richard Deeming 1-Sep-15 12:15pm    
Which part of "you need to change ANSI_PADDING setting before you can create an index on a computed column" didn't make sense?
RedDk 2-Sep-15 0:14am    
SET ANSI_PADDING OFF. Start there.

1 solution

The general formula is here
Alter table ForeignKeyTable add constraint ForeignKeyTable_ForiegnKeyColumn_FK
FOREIGN KEY (ForiegnKeyColumn) references PrimaryKeyTable (PrimaryKeyColumn)



see this link for more help


http://csharp-video-tutorials.blogspot.co.uk/2012/08/creating-and-working-with-tables-part-3.html[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900