Microsoft Azure Data FundamentalsDescribe how to work with relational data on AzureMedium
A developer is creating a new table in an Azure SQL Database that will store product information. Each product must have a unique identifier that is automatically generated and incremented by 1 each time a new product is added. The identifier should start at 1000. Which SQL Server property should be used for this column?
- ADEFAULT
- BPRIMARY KEY
- CIDENTITY
- DUNIQUE
Show answer & explanationAnswer & explanation
Correct answer: C. IDENTITY
The IDENTITY property in SQL Server automatically generates numeric values for a column, with a specified seed (starting value) and increment. In this case, IDENTITY(1000,1) would meet the requirements.
Why the other options are wrong
- A. DEFAULT assigns a default value if no value is explicitly provided during insertion, but not an auto-incrementing one.
- B. PRIMARY KEY enforces uniqueness and non-nullability but does not automatically generate values.
- D. UNIQUE ensures all values in a column are distinct but does not automatically generate them.
IDENTITY Property (SQL)
A column property in SQL Server that automatically generates sequential numeric values for new rows inserted into a table.
- Syntax: IDENTITY(seed, increment).
- Seed is the starting value, increment is the value added for each new row.
- Commonly used for primary key columns to ensure unique identifiers.
Memory trick: Identity: Each new row gets its own ID.