Like a table, we always prefer to make identity as primary key like identity(1,1) That way, that column will start 1 increment 1 when adding new row.
So could I ask whether I can add one row with specified number manually, like I can add one row with primary key 100
CREATE TABLE school ( student_id INT IDENTITY, student_name VARCHAR(200), marks INT ); Here, the 'student_id' column of the table starts from 1 as the default value of seed is 1 and each row is incremented by 1.
Each table can only have one primary key. Access can automatically create a primary key field for you when you create a table, or you can specify the fields that you want to use as the primary key.
set Identity_Insert yourtable on
Then do the insert
insert yourtable (id, field) values(100,'hello')
Then turn it off again
set Identity_Insert yourtable off
Yes you can. Using SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }
:
SET IDENTITY_INSERT YourTable ON
INSERT YourTable(Id, OtherField)
VALUES (100, 'Other Value')
SET IDENTITY_INSERT YourTable OFF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With