Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negative Primary Keys

Tags:

Are there any repercussions using Negative Primary Keys for tables (Identity Increment -1, Identity Seed -1 in SQL Server 2005)?

The reason for this is we're creating a new database to replace an existing one. There are similar tables between the two databases and we'd like the "source" of the information to be transparent to our applications. The approach is to create views that unions tables from both databases. Negative PKs ensures the identities don't overlap.

like image 622
bjaxbjax Avatar asked Mar 18 '10 20:03

bjaxbjax


People also ask

Can a primary key be negative?

No there's nothing inherently wrong with negative values in a primary key.

Can a foreign key be negative?

You cannot just enter any value in a FK field, the value you enter (negative or not) MUST exist in the referenced table.

What is a bad primary key?

Primary Key Example The student's first and last name are not good choices because there is always the chance that more than one student might have the same name. Other poor choices for primary keys include ZIP code, email address, and employer, all of which can change or represent many people.

Is negative value allowed in Identity in SQL?

Did you know that Identity Value can have a negative value?


1 Answers

Like others have said, the database is fine with this.

But it would be a problems for a .NET application that uses DataSet+DataAdapter as they use negative keys as temporaries for new records.

Other data-access layers may use similar tricks.

like image 165
Henk Holterman Avatar answered Sep 22 '22 21:09

Henk Holterman