Link to home
Start Free TrialLog in
Avatar of epmo
epmo

asked on

primary keys

do primary keys have an autonumber funcionality? if not, how do you handle unique id's?

tks.
Avatar of jrb1
jrb1
Flag of United States of America image

Primary Keys aren't autonumber by definition.  In fact, many primary keys are strings or multiple columns.  However, most databases do have a sequnece that you can use to autonumber a column.  That with a trigger could make it automatic.  What DB?
Sorry....obvously SQL Server.  You can also use an identity:

create table #a (id int identity, j int)

and this will generate a squential number on insert.
Avatar of epmo
epmo

ASKER


thanks jrb1, do i need to insert any values into it when inserting records?
Avatar of epmo

ASKER

i mean, we get an error when inserting records on the primary key - Cannot insert the value NULL into column ..
ASKER CERTIFIED SOLUTION
Avatar of jrb1
jrb1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You cannot insert nulls into a Primary key column - if the primary key column is also a identity column - this will autonumber the column.