Keys Flashcards

1
Q

What is the difference between an Intelligent or Natural key and a surrogate key?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the typical options used to create Surrogate Keys?

A
  1. The identity column property
  2. The sequence object
  3. Nonsequential GUIDs
  4. Sequential GUI Ds
  5. Custom solutions

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the Identity column property do?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Sequence Object?

A

It’s an independent object in the database that you can get a new sequence of values from.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What data types are supported when using the Sequence Object?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How is the Sequence Object different from the Identity Property?

A

It is not tied to a particular column, it is independent.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between UNIQUEIDENTIFIER and GUID?

A

There is none, they are the same thing. The UNIQUEIDENTIFIER data type stores non–sequential GUIDs.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you generate a new non–sequential GUID?

A

You use the function NEWID.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a GUID?

A

It is a globally unique identifier. They are guaranteed to be unique across space and time.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you generate a sequential GUID?

A

You use the function NEWSEQUENTIALID.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a natural key?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is one good way to name your PK column?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When creating a foreign key, what must be unique?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a surrogate key?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Should you use a natural key or surrogate key as a primary key?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do data types affect FK?

A

The FK must have the same data types as the column(s) it is referencing

SQL Server 70-461 08-02