Monthly Archives: June 2008 - Page 2

Difference between TRUNCATE and DELETE command

Lets see the difference between DELETE and TRUNCATE command as below

DELETE

TRUNCATE

DML Statement

DDL Statement

Data Rollback is possible, all the row by row data deletion will be recorded in transaction log

Rollback is possible for entire table and not at row level, since data page reallocation will be logged in transaction log

Eg.)

BEGIN TRAN

TRUNCATE Table Tablename

ROLLBACK

No Commit is performed neither before nor after. (Because it is a DML Statement)

It issues a COMMIT before it acts and another COMMIT afterward so no rollback of the transaction is possible. (Because it is a DDL Statement)

Row level locking will happen while performing deletion

Table level locking will be happen while performing truncation

A delete does not move the High Water Mark of the table back to zero, it retains its original position.

A truncate moves the High Water Mark of the table back to zero

WHERE statement can be included

WHERE statement cannot be included

Activates DML trigger

Doesn’t activate DDL trigger

Able to execute the command on the table that contains foreign key

Not able to execute the command on the table that contains foreign key

Consume more resources since need to process row by row and all these are logged operation

Consume less resource since it will process the full table and its non-logged operation

Lets discuss the above points using an example

Read more »

VN:F [1.9.13_1145]
Rating: 4.3/5 (3 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

SQL Server 2008 RC0 released

Microsoft has finally released RC0 version of SQL Server 2008. This is a pre-release version which is available to users to test and report SQL Server 2008 new features and funcionality. This installation of SQL Server 2008 will automatically expire after 180 of installation.

You can download the same from the link “Download SQL Server 2008

Supported OS to install SQL Server 2008

  • Windows XP Service Pack 3
  • Windows Server 2003 Service Pack 2
  • Windows Vista Service Pack 1
  • Windows Server 2008

If you find any bug you can post @ “SQL Server Connect

You can post your queries related to SQL Server 2008 @ “Katmai MSDN Forums” and “SQL Server 2008

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Finding Out SQL Server CPU usage Using T-SQL Code

Hi Friends,

In many companies developers won’t be given administrator privilege in OS on their test or development machines. When they execute a query and consider its consuming high CPU usage, since they won’t have admin privilege they are not able to confirm that the CPU is consumed by sqlservice or not. I’ve written a T-SQL Code to check the CPU usage consumed by Sqlservice.
Check out the below script.

Code:

DECLARE @CPU_BUSY int, @IDLE int
SELECT @CPU_BUSY = @@CPU_BUSY, @IDLE = @@IDLE WAITFOR DELAY ’000:00:01′
SELECT (@@CPU_BUSY – @CPU_BUSY)/((@@IDLE – @IDLE + @@CPU_BUSY – @CPU_BUSY) *1.00) *100 AS ‘CPU Utilization by sqlsrvr.exe’

Output:

CPU Utilization by sqlsrvr.exe
—————————————
0.850000000000000

Hope this small script will help you to check out sqlservice usage via T-SQL Statement!

VN:F [1.9.13_1145]
Rating: 3.3/5 (4 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 5 votes)

How to find TCP\IP port via T-SQL

In most of the forums I’ve seen that users are not able to find on which port does their sql server is listening. Hence I decided to write a script to check TCP\IP port on which sql server is listening. Checkout the below script.

Script

DECLARE @key VARCHAR(50), @RegistryPath VARCHAR(200)
IF (SERVERPROPERTY('INSTANCENAME')) IS NULL
BEGIN
SET @RegistryPath='Software\Microsoft\MSSQLServer\MSSQLServer\SuperSocketNetLib\Tcp\'
END
ELSE
BEGIN
SET @RegistryPath='Software\Microsoft\Microsoft SQL Server\'+CONVERT(VARCHAR(25),SERVERPROPERTY('INSTANCENAME')) + '\MSSQLServer\SuperSocketNetLib\Tcp\'
END
EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE', @RegistryPath, 'tcpPort'

Output

Value Data
tcpPort 1433
VN:F [1.9.13_1145]
Rating: 5.0/5 (2 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)
  • Page 2 of 2
  • <
  • 1
  • 2