Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ADD a named default to an exisitng column

Author  Topic 

Exgliderpilot
Starting Member

14 Posts

Posted - 2011-06-17 : 04:28:02
Hi I'm trying to add a named default sequential guid to an exisitng column in an existing table. I've looked up the MS help, pasted the tempate for this and removed the bits i dont need and ive got the following:

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[SetupPage]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[SetupPage](
[PageName] [varchar](100) NULL,
[PageDescription] [varchar](512) NULL,
[SetupPageGUID] [uniqueidentifier] NOT NULL,
[ApplicationId] [uniqueidentifier] NULL,
[row] [int] IDENTITY(1,1) NOT NULL,
CONSTRAINT [PK_SetupPage] PRIMARY KEY NONCLUSTERED
(
[SetupPageGUID] ASC
)WITH FILLFACTOR = 98 ON [PRIMARY]
) ON [PRIMARY]

GO

If NOT EXISTS(select 1 from sys.check_constraints where name='DF_SetupPage_SetupPageGUID')
ALTER TABLE [dbo].[SetupPage] ALTER COLUMN SetupPageGUID ADD CONSTRAINT DF_SetupPage_SetupPageGUID DEFAULT (newsequentialid()) FOR [SetupPageGUID]

I get the error: Incorrect syntax near the keyword 'CONSTRAINT'.

the correct synatax would very much be appreciated thanks


Staff bank ageny software http:\\www.ava.co.uk
   

- Advertisement -