212k views
2 votes
Which of the following statements represents a correctly structured transaction?

a. Begin; insert into album (album id, title, artist id) values (400, 'new album', 5); insert into playlist (playlist id, name) values (40, 'top 40'), (41, 'top 40'), (42, 'top 40'); insert into album (artist id, title, album id) values (1, 'my album', 348); commit;

b. Begin insert into album (album id, title, artist id) values (400, 'new album', 5) insert into playlist (playlist id, name) values (40, 'top 40'), (41, 'top 40'), (42, 'top 40') insert into album (artist id, title, album id) values (1, 'my album', 348) commit

c. Begin insert into album (album id, title, artist id) values (400, 'new album', 5); insert into playlist (playlist id, name) values (40, 'top 40'), (41, 'top 40'), (42, 'top 40'); insert into album (artist id, title, album id) values (1, 'my album', 348); commit;

d. Begin; commit; insert into album (album id, title, artist id) values (400, 'new album', 5); insert into playlist (playlist id, name) values (40, 'top 40'), (41, 'top 40'), (42, 'top 40'); insert into album (artist id, title, album id) values (1, 'my album', 348); commit;

User Debarshi
by
7.6k points

1 Answer

3 votes

Final answer:

The correct option for a properly structured SQL transaction is option c, which starts with a 'Begin' statement, ends with a 'Commit' statement, and separates each SQL statement with a semicolon.

Correct option is A

Step-by-step explanation:

The question refers to the structure of SQL transactions. The correct statement for a structured transaction is option c. In SQL, each statement within a transaction should be ended with a semicolon, and the transaction itself should start with a Begin (or Begin Transaction) statement and end with a Commit statement. The format usually looks like this:

Begin;
insert into table_name (column1, column2) values (value1, value2);
...
Commit;

Begin insert into album (album id, title, artist id) values (400, 'new album', 5);
insert into playlist (playlist id, name) values (40, 'top 40'), (41, 'top 40'), (42, 'top 40');
insert into album (artist id, title, album id) values (1, 'my album', 348);
Commit;

Each statement is separated by a semicolon, and the transaction is correctly begun and committed.

User Rahma Samaroon
by
8.8k points