At work we have a large database with a unique index instead of the primary key and all functions are fine.
I am preparing a new database for a new project and I have a dilemma:
In DB theory, the primary key is the fundamental element, it is fine, but the real projects What are the advantages and disadvantages of both?
What do you use in projects?
Edit: ... and what about the primary key and replication on MS SQL Server?
What is a unique index?
A unique index on the column The index that applies the barrier to the column, in that column, you can not have two identical values in two similar lines Example:
Create table table 1 (foo int, bar int); Create unique index ux_table1_foo on Table 1 (Foo); - Create unique index on foo Table 1 (FU, bar) Include in values (1, 2); - Insert table 1 (AF, band) values right (2, 2); - Insert the table 1 (FU, bar) values correctly (3, 1); - INSERT (1, 4) right in Table 1 (AF, bar) values; - Fail! The duplicate entry '1' for the key 'ux_table1_foo' fails because the column violates the unique index onfoo
, when it tries to insert value 1 into this column second time.A unique obstacle in MySQL allows multiple plays.
It is possible to create a unique index on multiple columns.
Primary key vs. unique index
Things that are similar:
- The meaning of the primary key is a unique index .
Things are different:
- The meaning of a primary key is also not zero, but a unique index can be null.
- Only one primary key can be, but there may be more than one unique index.
- If no package index is defined then the primary key will be the package index.
Comments
Post a Comment