About 56 results
Open links in new tab
  1. How can I alter a primary key constraint using SQL syntax?

    Dec 17, 2021 · 134 I have a table that is missing a column in its primary key constraint. Instead of editing it through SQL Server, I want to put this in a script to add it as part of our update scripts. What …

  2. sql server - SQL-script: How to write ALTER statements to set Primary ...

    SQL-script: How to write ALTER statements to set Primary key on an existing table? Asked 13 years, 6 months ago Modified 1 year, 9 months ago Viewed 1.1m times

  3. SQL Server Change Primary Key Data Type - Stack Overflow

    Jan 9, 2017 · I am working on SQL Server 2012: I have a table with a primary key column as INT. I need to change this to a GUID. Do I alter the table and remove int column as primary key? Add the GUID …

  4. SQL Server add auto increment primary key to existing table

    This answer is a small addition to the highest voted answer and works for SQL Server. The question requested an auto increment primary key, the current answer does add the primary key, but it is not …

  5. Change primary key column in Microsoft SQL Server

    ALTER COLUMN id int NOT NULL ALTER TABLE history ADD PRIMARY KEY (id) ALTER TABLE history DROP CONSTRAINT userId DROP CONSTRAINT name GO I've only gotten to the attempt …

  6. sql - Turn existing column into a primary key - Stack Overflow

    Apr 15, 2014 · ADD CONSTRAINT x PRIMARY KEY is cleaner, since you can name the PK, instead of letting SQL Server add a cryptic random name to the all-important Primary Key

  7. sql - Adding column with primary key in existing table - Stack Overflow

    ALTER TABLE Product_Details ADD CONSTRAINT pk_Product_Detils_Product_Detail_ID PRIMARY KEY(Product_Detail_ID) The CREATE UNIQUE INDEX statement terminated because a duplicate …

  8. How to make Primary Key in Sql Server Using Alter Statement?

    Apr 26, 2014 · 0 I have forgot create a primary key for my table. Now I want to update the DocDay_Id column and make it the primary key. How can I do it? My code is below. I tried this syntax but it is not …

  9. How to change the column length of a primary key in SQL Server?

    May 20, 2015 · 29 I know how to change the length of a column, but my SQL statement fails because the column I'm trying to change is a PK, so I get the following error: Msg 5074, Level 16, State 1, …

  10. sql - How to change the primary key to be non-clustered ... - Stack ...

    Apr 9, 2010 · Part-time reluctant DBA here. I want to change an existing primary key index from clustered to non-clustered. And the syntax is escaping me. This is how it's scripted out right now. …