You want to add a new GUID column named BookGUID toa table named dbo.Book that already contains data.
BookGUID will have a constraint to ensure that it always has a value when new rows are inserted into dbo.
Book. You need to ensure that the new column is assigned a GUID for existing rows. Which four Transact-SQL
statements should you use? (To answer, move the appropriate SQL statements from the list of statementsto
the answer area and arrange them in the correct order.)
Answer:
Explanation:
Verified answer as correct.
Actually, in the real world, you don’t have to use WITH VALUES at the end of the statement and it works just as
well. But because the question specifically states which FOUR TSQL statements to use, we have to include it.
Reference: http://msdn.microsoft.com/en-us/library/ms190273.aspx
If the new column is NOT “nullable” column then no need to use “WITH VALUES” key word.
It works as bellow:
CREATE TABLE book(
name varchar(25)
)
INSERT INTO book (name) VALUES (‘book 1’)
INSERT INTO book (name) VALUES (‘book 2’)
INSERT INTO book (name) VALUES (‘book 3’)
INSERT INTO book (name) VALUES (‘book 4’)
INSERT INTO book (name) VALUES (‘book 5’)
—
ALTER TABLE book ADD bookGuid uniqueidentifier NOT NULL
CONSTRAINT DF_BookGuid DEFAULT NEWID();
—
SELECT * FROM book
4 options you only used 3.