0

I'm new to SQL. I created a table and filled it with some data. Now I want to change the properties of my primary key, so it will auto increment every single time by itself when adding data.

I know how to do it when creating a table, but where do I add auto_increment now, when I already have a created table with filled data?

Faizy
  • 299
  • 2
  • 12
  • 2
    Which RDBMS is this for? Please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s May 29 '16 at 14:19

2 Answers2

1

Update

Try

ALTER TABLE [TableName] DROP COLUMN ID 
ALTER TABLE [TableName] ADD ID INT IDENTITY(1,1)

If you had entered data to your table review this link that have an answer to you question SQL Server, How to set auto increment after creating a table without data loss?

Community
  • 1
  • 1
Muhammad Hassan
  • 475
  • 2
  • 14
  • If you had entered data to your table review this link that have an answer to you question [SQL Server, How to set auto increment after creating a table without data loss?](http://stackoverflow.com/questions/6084572/sql-server-how-to-set-auto-increment-after-creating-a-table-without-data-loss) – Muhammad Hassan May 29 '16 at 14:51
0

You can't change logical structure column when you have some filled data in column. That's impossible. You must deleting data from column and use ALTER TABLE to change properites column

starko
  • 1,150
  • 11
  • 26
  • @Faizy This all depends on the DBMD being used. This is very well possible e.g. in Postgres –  May 29 '16 at 15:14