Great! We've reached the final section for this part. Let's review what we've learned.
A database architect can define a default value for a column in a table. If that's the case, you can use default value:
INSERT INTO Author (Id, FirstName, LastName, Photo, CreateDateTime, IsActive)
VALUES (120, N'Gary', N'Brown', N'imgs/gary.jpg', '2018-08-25', DEFAULT);
By omitting columns in
INSERT INTO Author (Id, FirstName, LastName)
VALUES (121, N'Mary', N'Taylor');
Photo = DEFAULT
WHERE Id = 120;
Plus, you learned how to auto-generate unique values by:
IDENTITY and omitting the name of the
INSERT INTO Author(FirstName, LastName)
VALUES (N'Stanley', N'Lewis');
Id column, which isn't listed in the query, uses
IDENTITY to auto-generate values unique to this column.
INSERT INTO Author (Id, FirstName, LastName, Photo)
VALUES (NEWID(), N'Eva', N'Rayan', N'imgs/lisa3.jpg');
Using a sequence:
INSERT INTO Author (Id, FirstName, LastName, IsActive)
VALUES (NEXT VALUE FOR IdSeq, N'Miriam', N'Clerk', 1);
Auto-generated values from the same sequence can be used in multiple tables, and each value will be unique.