SELECT returns data.
SET assigns values to local variables.
While testing the performance of the following two scripts in query analyzer, interesting results are discovered.
SET @foo1 = 1;
SET @foo2 = 2;
SET @foo3 = 3;
SELECT
@foo1 = 1,
@foo2 = 2,
@foo3 = 3;
While comparing their performance in loop SELECT statement gives better performance then SET. In other words, SET is slower than SELECT. The reason is that each SET statement runs individually and updates on values per execution, whereas the entire SELECT statement runs once and update all three values in one execution.
SET is the ANSI standard for variable assignment, SELECT is not. SET can only assign one variable at a time, SELECT can make multiple assignments at once – that gives SELECT slight speed advantage over SET. If assigning from a query, SET can only assign a scalar value. If the query returns multiple values/rows then SET will raise an error. SELECT will assign one of the values to the variable and hide the fact that multiple values were returned. When assigning from a query if there is no value returned then SET will assign NULL, where SELECT will not make the assignment at all keeping the variable unchanged.
ASP.NET, C#, VB.NET, SQL SERVER, SILVERLIGHT, AJAX, JAVA SCRIPTS, CSS, HTML, WCF, WPF,WIX, APEX and More...
Sunday, August 7, 2011
Thursday, July 28, 2011
Wednesday, January 26, 2011
Shrink Log File - SQL
The log file (.log) of the SQL database will keep the track of all transactions happend to the database. As the transaction increases the log file size will get increase.
The following command will help you to shrink (reduce the log file size) your log file, ie. it will remove all the log from the log file.
To get the list of Log file
select name from sys.database_files where type = 1
To Shrink the Log file
DBCC SHRINKFILE('mastlog');
if Still the log file didnt get shinked, there could be a uncommitted transactions.
Execute the following command to get the list of acive transaction
DBCC OPENTRAN('WorkOrders');
Once all the active transactions are closed, then again execute the shrinkfile command
The following command will help you to shrink (reduce the log file size) your log file, ie. it will remove all the log from the log file.
To get the list of Log file
select name from sys.database_files where type = 1
To Shrink the Log file
DBCC SHRINKFILE('mastlog');
if Still the log file didnt get shinked, there could be a uncommitted transactions.
Execute the following command to get the list of acive transaction
DBCC OPENTRAN('WorkOrders');
Once all the active transactions are closed, then again execute the shrinkfile command
Subscribe to:
Posts (Atom)