SQL Interview: 10 System-defined default names
This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.
Section: Development Level: Medium
Question:
When you define a column default with code like below:
USE tempdb;
GO
DROP TABLE IF EXISTS dbo.Customers;
GO
CREATE TABLE dbo.Customers
(
CustomerID int IDENTITY(1,1)
CONSTRAINT PK_dbo_Customers PRIMARY KEY,
TradingName nvarchar(100) NOT NULL,
CreatedDate datetime2(3) NOT NULL DEFAULT (SYSDATETIME())
);
GO
the system will define the name of the default. Can you give examples of why specifying the name of the default instead of letting the system supply it would be a good practice?
2021-04-15