Monday, January 11, 2010

T-SQL

CREATE TABLE test4(id int PRIMARY KEY IDENTITY(1,1),DESCr int)


INSERT INTO test4(DESCr)
VALUES(1)

SELECT * FROM test4 t


SET IDENTITY_INSERT dbo.test4 on
INSERT INTO test4(id,DESCr)
VALUES(7,3)
SET IDENTITY_INSERT dbo.test4 off



USE AdventureWorksDW
go


--CREATE TABLE test(id int)
--TRUNCATE TABLE test


BEGIN TRAN
PRINT @@TRANCOUNT

BEGIN try

INSERT INTO test(id)
VALUES(2)
SELECT * FROM test
END try
BEGIN catch
if @@error <> 0
begin
ROLLBACK
SELECT ERROR_MESSAGE()
PRINT @@TRANCOUNT
end
else
begin
COMMIT
PRINT @@TRANCOUNT
end
END catch

No comments: