Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 transaction

Author  Topic 

whitepear
Starting Member

24 Posts

Posted - 2014-04-19 : 03:50:47
Hello!
Please, this is hte first transaction I made in my life, and I am not sure I understand what is actually happening there.

I actually do not understand the line :
when others then

others stands for a certain condition, which is in this case "general".

Please, could someone explain me clearly what is happening in this line.

BEGIN TRANSACTION;

DROP TABLE IF EXISTS PUPIL;

CREATE TABLE PUPIL(
PN INTEGER PRIMARY KEY,
PNAME TEXT
);

COMMIT;

BEGIN TRANSACTION;
INSERT INTO PUPIL VALUES(1,'AAA');
INSERT INTO PUPIL VALUES(2,'BBB');
INSERT INTO PUPIL VALUES(3,'CCC');
INSERT INTO PUPIL VALUES(4,'DDD');
COMMIT;

SELECT * FROM PUPIL;
BEGIN;
SAVEPOINT SPX;

INSERT INTO PUPIL VALUES(5,'EEE');
INSERT INTO PUPIL VALUES(6,'FFF');
COMMIT;

BEGIN TRANSACTION;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO SPX
raise_application_error(-20100, SQLRRM);
END;


SELECT * FROM PUPIL;


P.S. eXECUTION IS:
1|AAA
2|BBB
3|CCC
4|DDD
Error: near line 28: near "EXCEPTION": syntax error
1|AAA
2|BBB
3|CCC
4|DDD
5|EEE
6|FFF


hOW DO i GET RID OF THE MISTAKE IN LINE 27?
mANY THANKS!!!

I just know, when condition = others, in that case rollback will undo insert in in 5th and 6th row of the table.

So, what is "others" meaning acutally?

Manny thanks and sorry for confusion!!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-04-19 : 07:19:33
are you using Microsoft SQL Server ? If not, try posting at other forum


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

whitepear
Starting Member

24 Posts

Posted - 2014-04-19 : 11:05:50
is is www.compileonline.com

/online compiler , also for sql

Which forum do u reccomad?
Many thanks!
Go to Top of Page
   

- Advertisement -