Microsoft Azure Data FundamentalsDescribe how to work with relational data on AzureEasy
A data architect is designing a new relational database in Azure. The database will store customer information, including names, addresses, and phone numbers. The architect needs to ensure that each customer record has a unique identifier that is automatically generated and incremented with each new record. Which SQL Server feature should the architect use for the customer ID column?
- APRIMARY KEY
- BUNIQUE
- CDEFAULT
- DIDENTITY
Show answer & explanationAnswer & explanation
Correct answer: D. IDENTITY
The IDENTITY property in SQL Server is specifically designed to generate unique, auto-incrementing numbers for a column, making it ideal for primary keys where new records need unique identifiers. PRIMARY KEY ensures uniqueness and non-nullability but doesn't auto-generate values.
Why the other options are wrong
- A. PRIMARY KEY ensures uniqueness and non-nullability for a column but does not automatically generate sequential values.
- B. UNIQUE ensures that all values in a column are distinct but does not automatically generate values.
- C. DEFAULT provides a default value for a column if no value is explicitly specified during insertion but does not generate unique, incrementing numbers.
IDENTITY Property (SQL)
A column property in SQL Server that automatically generates sequential numeric values when new rows are inserted into a table, commonly used for auto-incrementing primary keys.
- Automatically generates unique, sequential numbers.
- Typically used for primary key columns.
- Defined with a 'seed' (starting value) and 'increment' (value to add).
Memory trick: Identity is the key to auto-generated numbers.