Some things I want to share with you for your question:
- You can not change the primary key column value as you gave auto-increment by 1. See the concept of identity: What does (1,1) mean in SQL?
the first 1 means the starting value of column and the second 1 means the increment value of column
Do not use SQL Server reserved words like empty
for your own database objects (like tables)
Not recommended, but still you want to modify, then try this, add new row(s) with the values and delete the row(s) (How to update Identity Column in SQL Server?)
)
You can not update identity column.
SQL Server does not allow to update the identity column unlike what you can do with other columns with an update statement.
--create table empty
--(
-- data_id int identity(1,1),
-- emp_name varchar(20),
-- address varchar(20),
-- city varchar(20)
--)
--select * from empty
--Insert into empty values
--('ritesh','210 b_block','sivapur'),
--('pritma','visvaas khand','lucknow'),
--('rakesh','nehru nagar','delhi')
select * from empty
SET IDENTITY_INSERT [empty] ON;
--give error as we do not change the auto increment column, so comment and then run
--update [empty]
--set data_id = 10 where data_id = 1;
INSERT INTO [empty] (data_id, emp_name, address, city)
SELECT 10 data_id, emp_name, address, city
FROM [empty]
WHERE data_id = 1;
SELECT * FROM [empty]
DELETE [empty]
WHERE data_id = 1;
SET IDENTITY_INSERT [empty] OFF;
SELECT * FROM [empty]