Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 5123

Question about Transaction's Atomicity property

$
0
0

Hi Guys,

According to Microsoft document about transaction, there is a feature called atomicity. 

https://technet.microsoft.com/en-us/library/ms190612(v=sql.105).aspx

Basically it means within a transaction, either all of its data modifications are performed, or none of them is performed.

Now I have the following T-SQL code

SET IMPLICIT_TRANSACTIONS OFF

CREATE TABLE class (c_id int primary key, c_name varchar(10))
INSERT INTO class VALUES (11, 'yuwen'),(12,'shuxue'),(13,'lishi')
CREATE TABLE student (s_id int primary key, s_name varchar(10), c_id int foreign key references class (c_id))

BEGIN TRANSACTION
	INSERT INTO student VALUES (1,'bill',11)
	INSERT INTO student VALUES (2,'bill',14)
COMMIT

SELECT * FROM student
Can anyone explain why when we are looking at the student table, we can see that the first INSERT statement performed successfully, while the second didn't. I read from book saying that "foreign key violations do not cause all the statements to roll back", however, this conflict against the very basic transaction requirement regarding atomicity. How should I think about this?


Viewing all articles
Browse latest Browse all 5123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>