StumbleUpon  Del.icio.us  Facebook  Reddit  Add to diigo  


Follow - Monx007
Article Time Stamp: 02 April 2012, 22:46:28 GMT+7

Microsoft SQL (MS SQL): Sample SQL Script to Check If A Table Exists



Let's say, that we want to check whether a table already exists in our database or not. We named our table as tbl_a. And if it doesn't exists, then we just print to the screen 'Not Exists' words. Otherwise, we just print 'Already Exists' words.


IF EXISTS (SELECT * FROM sys.objects WHERE name = 'tbl_a' and type_desc = 'USER_TABLE')
PRINT 'Already Exists'

ELSE
PRINT 'Not Exists'



Or you can also use this SQL statements:


IF OBJECT_ID('tbl_a') IS NOT NULL
print 'Already Exists'
else
print 'Not Exists'



Article Source: Monx Digital Library

Copyrighted@ Monx Digital Library, otherwise stated
Use of our service is protected by our Terms of Use



 Back To Previous Page ...  



 

 

 

AQWorlds Nulgath Secret Walkthrough