Keys Flashcards
What is the difference between an Intelligent or Natural key and a surrogate key?
An Intelligent or Natural key is a key made from a data attribute that already exists. For example social security number.
A surrogate key has no meaning associated with the value.
SQL Server 70-461 02-02a
What are the typical options used to create Surrogate Keys?
- The identity column property
- The sequence object
- Nonsequential GUIDs
- Sequential GUI Ds
- Custom solutions
SQL Server 70-461 02-02a
What does the Identity column property do?
It automatically generates keys in one of the following data types:
TINYINT
SMALLINT
INT
BIGINT
NUMERIC with scale of 0
DECIMAL with scale of 0
SQL Server 70-461 02-02a
What is the Sequence Object?
It’s an independent object in the database that you can get a new sequence of values from.
SQL Server 70-461 02-02a
What data types are supported when using the Sequence Object?
Just like the Identity Property, any numeric data type is supported. Any numeric data type that uses scale must have a scale of 0.
TINYINT
SMALLINT
INT
BIGINT
NUMERIC with scale of 0
DECIMAL with scale of 0
SQL Server 70-461 02-02a
How is the Sequence Object different from the Identity Property?
It is not tied to a particular column, it is independent.
SQL Server 70-461 02-02a
What is the difference between UNIQUEIDENTIFIER and GUID?
There is none, they are the same thing. The UNIQUEIDENTIFIER data type stores non–sequential GUIDs.
SQL Server 70-461 02-02a
How do you generate a new non–sequential GUID?
You use the function NEWID.
SQL Server 70-461 02-02a
What is a GUID?
It is a globally unique identifier. They are guaranteed to be unique across space and time.
SQL Server 70-461 02-02a
How do you generate a sequential GUID?
You use the function NEWSEQUENTIALID.
SQL Server 70-461 02-02a
What is a natural key?
- A column or combination of columns that uniquely identify each row.
- An example would be category name in production.categories table
SQL Server 70-461 08-02
What is one good way to name your PK column?
- Simple TableNameID
- Example: categoryID
- When used as a FK in another table it will be clear what table it comes from and that it is an id column.
SQL Server 70-461 08-02
When creating a foreign key, what must be unique?
- The value you are looking up in the other table with the FK
- In other words if the FK value is 2 there must be only one value of 2 in the table it is looking it up in
SQL Server 70-461 08-02
What is a surrogate key?
A column that has a unique value that has no meaning in the form of a numeric data type (such as integer)
SQL Server 70-461 08-02
Should you use a natural key or surrogate key as a primary key?
A surrogate key is better in the long run. What would happen if the business decided to change the data in the natural key column and it was the PK column? Much more painful. Use surrogate key as PK and enforce uniqueness of natural key using a unique constraint.
SQL Server 70-461 08-02