Thursday, September 11, 2008

SQL Stuff

--- Database transactions
begin tran
rollback tran
Save Transaction tran_name

--Deletes last row inserted in table Employees

declare @topN int
set @topN = 1
set rowcount @topN
Delete From Employees


--Makes ROWCOUNT Off

--Once the rowcount is set , it is set until you explicitly make off
Set ROWCOUNT 0

Important :
When a transaction begins,
resources used during the transaction are held until the completion of the transaction
(namely locks).
When part of a transaction is rolled back to a savepoint, resources
continue to be held until the completion of the transaction
(or a rollback of the complete transaction).


@@TRANCOUNT
Returns the number of active transactions for the current connection.

@@ROWCOUNT
Returns the number of rows affected by the last statement.

@@IDENTITY
Returns the last-inserted identity value.

@@FETCH_STATUS
Returns the status of the last cursor FETCH statement issued against any cursor currently opened by the connection.

Return value Description
0 FETCH statement was successful.
-1 FETCH statement failed or the row was beyond the result set.
-2 Row fetched is missing.

@@ERROR
Returns the error number for the last Transact-SQL statement executed.

@@DBTS
Returns the value of the current timestamp data type for the current database. This timestamp is guaranteed to be unique in the database.

Creates a user-defined data type.
sp_addtype [ @typename = ] type,
  [ @phystype = ] system_data_type
  [ , [ @nulltype = ] 'null_type' ]
  [ , [ @owner = ] 'owner_name' ]

No comments: