About 501,000 results
Open links in new tab
  1. SQL-script: How to write ALTER statements to set Primary key on an ...

    In this table I have 5 fields: personId Pname PMid Pdescription Pamt The table already has an existing compound-key [PersonId, Pname] as the primary key. Now I want to modify that existing compound …

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

    The question requested an auto increment primary key, the current answer does add the primary key, but it is not flagged as auto-increment. The script below checks for the columns, existence, and adds …

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

    Your table has duplicate values in this column, but a primary key requires that the values within the column are unique. In order to create the PK, you must remove the duplicates.

  4. sql - Adding an identity to an existing column - Stack Overflow

    Jun 26, 2009 · 577 I need to change the primary key of a table to an identity column, and there's already a number of rows in table. I've got a script to clean up the IDs to ensure they're sequential starting at …

  5. How to add a primary key to a MySQL table? - Stack Overflow

    Aug 28, 2015 · Existing Column If you want to add a primary key constraint to an existing column all of the previously listed syntax will fail. To add a primary key constraint to an existing column use the form:

  6. How to add a primary key and foreign key to an existing table in ...

    Mar 3, 2017 · Defining Primary and Foreign Keys do not create a new table, they create relationships between the table. Their primary purpose is to ensure data consistency; joins can be performed on …

  7. ALTER TABLE to add a composite primary key - Stack Overflow

    Jan 14, 2012 · 240 I have a table called provider. I have three columns called person, place, thing. There can be duplicate persons, duplicate places, and duplicate things, but there can never be a …

  8. automatically insert auto increment primary key and values into ...

    ALTER TABLE tbl ADD id INT PRIMARY KEY AUTO_INCREMENT; On a temporary table created for testing purposes, the above statement created the AUTO_INCREMENT id column and inserted auto …

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

    Apr 15, 2014 · create table emp ( emp_id int, emp_name varchar(40) not null, emp_address varchar(35) not null, ) Now I need to add primary key to emp_id . I tried using alter query alter table emp add cons...

  10. Add a auto increment primary key to existing table in oracle

    Jul 13, 2012 · Closed 10 years ago. I want to add a new auto increment primary column to a existing table which has data. How do I do that? I first added a column and then try to add a sequence after …