|
|
-
|
|
Suppose you want to find out the name of the procedure that calls the procedure being executed,you can use system function @@PROCID which returns the object id of the current procedure.
Consider the following procedures. test1 calls the procedure test2 which actually logs some informations to the ......
|
|
-
|
|
Here are the three different ways to know the Server name using queries
Method 1 : Use @@servername
select @@servername as server_name
Method 2 : Use sp_helpserver system procedure
exec sp_helpserver
Method 3 : Use sys.sysservers view
select srvname from sys.sysservers
......
|
|
-
|
|
Many programming languages like VB6 support IIF function which is used to return a value based on a particular expression/condition. In SQL Server the equivalent is to make use of CASE Expression, which is used to evaluate many conditions and return a single value. The following examples will give y......
|
|
-
|
|
As you know, @@TRANCOUNT is used to inform you about the number of live transactions active at point. If you want to retrieve it's value using an application, you should be careful about the behaviour of the returned value. Let us consider the procedure
create procedure get_count
as
select @@TRA......
|
|
-
|
|
One of my friends asked me if it is possible to identify the tables with identiy columns as he wanted to run dbcc checkident command to all the tables of the database.There are actually many ways to identify identity columns from a table.The following three methods will list out the table names and ......
|
|
-
|
|
IF..ELSE clause in SQL Server is used for decision making. You can use it to run a set of statements based on certain conditions. The following are the examples on how to use it effectively for various purposes. Simple Decision making example
declare @status bit
set @status=1
if @status=0
prin......
|
|
|
|
-
|
|
For various reasons you may need to audit some activities on certain tables.Usually you can use triggers for this.Sometimes you may want to know the system from which data are added or the user who added data.In these cases, you can use two functions host_name() and user_name()
Host_name() This fun......
|
|
-
|
|
As you know well, VALUES clause is used to insert values to the table
A simple example is
declare @t table (id int , col1 int, col2 int, col3 int)
insert into @t values(1, 14, 12, 24)
select * from @t
But in version 2008, you can do more things using VALUES clause than the previous versions......
|
|
-
|
|
Sometimes back, my friend told me that they had an application where users update their timesheets. He suspected that some users who had access to the database directly update some entries. He wanted to know whether some users update entries using a query analyser and not using the application. You ......
|
|