Wednesday, May 20, 2009

Unlock the table in Sql Server 2005

By using SP_Lock you get the info on the locks, I means locks on the objects like Tables. You can also find the SPID (Processor Id) which is locking this.
By using Kill command you can kill the processor which intern releases the locks.
Following is the example:
EXEC sp_lock --> all the objects with the lock info and find the processor locking the required object let us ay spid is 54

or
dbcc opentran
dbcc inputbuffer(yourprocessid)

KILL 54 --> this will kill the processor id 54.
Please make sure that you are killing only the processor which is locking your objects.

Monday, May 11, 2009

Difference between Stored Procedure and Function

1. You cannot use stored procedure in a select statement likeselect but this is possible with UDF .
2. You can not return a table type variable with stored procedure but this is possible with user defined functions in sql Server.
3. Stored procedure may or may not return a value but a function has to return a value.
4. UDFs can accept a smaller number of parameters than stored procedures. UDFs can have up to 1024 parameters, whereas stored procedures support up to 2100 parameters. This is a relatively minor limitation because most routines require a much smaller number of parameters.
5. UDFs cannot call stored procedures (except extended procedures), whereas stored procedures can call other procedures.

Friday, May 8, 2009

Difference Between @@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT


@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions because they all return the last value inserted into the IDENTITY column of a table.
@@IDENTITY and SCOPE_IDENTITY return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.

The scope of the @@IDENTITY function is current session on the local server on which it is executed. This function cannot be applied to remote or linked servers.