July 2, 2014 at 8:26 am
Hi,
I created a table in my Azure SQL Database, Part of the code is here..
CREATE TABLE [dbo].[DEVAppointments](
[ClusterInd] [int] IDENTITY(1,1) CONSTRAINT PK_CI_DEVAppt PRIMARY KEY CLUSTERED NOT NULL,
[dbPatFlowArcCnt] [int] NOT NULL,
I now wish to make the column dbPatFlowArcCnt a Primary Key column too but don't wish to drop the table as it has lots of data in it.
When I use this sql however..
alter table DEVAppointments drop CONSTRAINT PK_CI_DEVAppt
alter table DEVAppointments add primary key (PK_CI_DEVAppt, dbPatFlowArcCnt)
I get this error
Msg 40054, Level 16, State 2, Line 9
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
Msg 3727, Level 16, State 0, Line 9
Could not drop constraint. See previous errors.
thanks,
July 2, 2014 at 8:40 am
I don't think you can change a primary key on Azure if the table has data in it. There's quite a few suggestions out there for workarounds but unfortunately it's not as simple as dropping the old one and creating a new one.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
July 2, 2014 at 12:26 pm
Since Azure requires a clustered index for every table with data in it, you can't alter it to change the clustered index.
July 2, 2014 at 12:30 pm
What you will need to do is create a new table with the structure you want. Then copy all the data from the current table into the new one. Drop the current table. Rename the new table to the name of the current one.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 3, 2014 at 7:29 am
Sometimes I wish I could just vote for answers here.
Karen has the cause, Sean has the solution.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply