PrepAway - Latest Free Exam Questions & Answers

Solution: You run the following Transact-SQL statement:…

Note: This question is part of a series of questions that present the same scenario. Each question in
the series contains a unique solution that might meet the stated goals. Some question sets might have
more than one correct solution, while others might not have a correct solution.
After you answer a question in this section. You will NOT be able to return to it. As a result, these
questions will not appear in the review screen.
You create a table named Customer by running the following Transact-SQL statement:

You must insert the following data into the Customer table:

You need to ensure that both records are inserted or neither record is inserted.
Solution: You run the following Transact-SQL statement:

Does the solution meet the goal?

PrepAway - Latest Free Exam Questions & Answers

A.
Yes

B.
No

Explanation:
As there are two separate INSERT INTO statements we cannot ensure that both or neither records are
inserted.

4 Comments on “Solution: You run the following Transact-SQL statement:…

  1. eder says:

    create TABLE test.town(
    townID int PRIMARY KEY NOT NULL,
    NameCity varchar(250)null
    )

    INSERT INTO test.town VALUES (1,’NEBRASKA’)
    INSERT INTO test.town VALUES (2,’Minnesota’)

    select * from test.town
    create TABLE test.customer(
    CustomerID INT IDENTITY(1,1)CONSTRAINT pk_customerID PRIMARY KEY CLUSTERED,
    FirstName VARCHAR(50)NULL,
    Lastname VARCHAR(50)NOT NULL,
    DateOfBirthday DATE NOT NULL,
    CreditLimit money CHECK (CreditLimit<10000),
    TownID int null references test.town(townID),
    CreatedDate DATETIME DEFAULT (GETDATE())
    )

    BEGIN
    SET XACT_ABORT ON
    BEGIN TRY
    BEGIN TRANSACTION
    INSERT INTO test.customer (FirstName,Lastname,DateOfBirthday,CreditLimit,CreatedDate)
    VALUES ('Yvonne','Mc Kay','1984-05-25',9000,getdate())
    INSERT INTO test.customer (FirstName,Lastname,DateOfBirthday,CreditLimit,CreatedDate)
    VALUES ('Jossef','Goldberg','1995-06-03',5500,getdate())
    COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
    THROW 51000,'ERROR CUSTOM!!!',1
    ROLLBACK TRANSACTION
    END CATCH
    END




    0



    0
  2. eder says:

    autocommit transaction:
    INSERT INTO test.customer (FirstName,Lastname,DateOfBirthday,CreditLimit,CreatedDate)
    VALUES (‘Yvonne’,’Mc Kay’,’1984-05-25′,9000,getdate()),(‘Jossef’,’Goldberg’,’1995-06-03′,5500,getdate())

    este tipo de insert asegura que se inserten las 2 filas o que no se inserte ninguna




    0



    0

Leave a Reply