Overview

CREATE TABLE

CREATE TABLE [User]
(
	-- Primary Key - Auto Number (Seed, Increment)
	[UserId] INT IDENTITY(1,1) NOT NULL,
	/* We can Set PRIMARY KEY on [UserId] this way: 
			-- [UserId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
			The difference is that the DBMS chooses the name of the primary key.
	*/
	/* Here we define the Constraint for the Primary key. */
	CONSTRAINT [PK_User_Id] PRIMARY KEY CLUSTERED ([UserId] ASC) ON [PRIMARY]
	[FirstName] NVARCHAR(40) NULL,
	[LastName] NVARCHAR(40) NOT NULL,
	[ParentUserId] INT NOT NULL
	CONSTRAINT [FK_dbo_User_dbo_User]
		FOREIGN KEY	([ParentUserId])
		REFERENCES [dbo].[User]([UserId])
		ON UPDATE CASCADE 
		ON DELETE CASCADE,
)

Add Computed Columns

ALTER TABLE [Production].[WorkOrder]
ADD [OrderVol] AS 
	CASE
		WHEN [OrderQty] < 10 THEN 'Single Digit' 
		WHEN [OrderQty] >= 10 AND [OrderQty] < 100 THEN 'Double Digit' 
		WHEN [OrderQty] >= 100 AND [OrderQty] < 1000 THEN 'Three Digit'
		ELSE 'Super Large'
	END PERSISTED