0

I'm trying to move a primary key from one database (SQL Server 2000) to another database. In the original database I have a primary key that I've used SSMS to script this to a new query window:

USE [DatabaseName_Test]
GO

ALTER TABLE [dbo].[tbl_itinerary_item] ADD  CONSTRAINT [PK_tbl_itinerary_item] PRIMARY KEY CLUSTERED 
(
    [activity_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

All I did was change the database:

USE [DatabaseName]
GO

ALTER TABLE [dbo].[tbl_itinerary_item] ADD  CONSTRAINT [PK_tbl_itinerary_item] PRIMARY KEY CLUSTERED 
(
    [activity_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

The error I get is

Msg 170, Level 15, State 1, Line 5 Line 5:
Incorrect syntax near '('.

What am I missing?

6
  • 2
    possible duplicate of Convert Single SQLSERVER 2005 Script to a SQL SERVER 2000 script Commented Jan 15, 2013 at 20:20
  • 2
    Are both databases of the same version? Commented Jan 15, 2013 at 20:22
  • AFAIK this part is understood on SQLServer 2005 for the first time : WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) Commented Jan 15, 2013 at 20:23
  • Yeah, @Pondlife has a good link to look at. Commented Jan 15, 2013 at 20:26
  • 1
    @Macness Yes, this question is actually an even better one to look at, because it gives a solution too (how to tell SSMS to generate SQL2000-compatible scripts). Commented Jan 15, 2013 at 20:43

1 Answer 1

1

Try to simplify your sql like this:

ALTER TABLE [dbo].[tbl_itinerary_item] ADD  CONSTRAINT [PK_tbl_itinerary_item] PRIMARY KEY 
(
    [activity_id] ASC
)ON [PRIMARY]
GO
Sign up to request clarification or add additional context in comments.

1 Comment

That certainly did the trick. The script was overcomplicating things. I work in both a SQL 2000 and 2008 R2 environment so the script seems to be more in line with options that can be used by 2005. I think

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.