Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Check existence of any table using PL-SQL in SQL server 2008.

Author: Zunnair

In this simple article you will learn that how you can check existence of any table using PL-SQL

In sql server 2008 we can check existence of any table by its name using If Exist function and after that we can perform any operation based on result of if exist function. It is very simple to implement in PL-SQL

 

Query:

 

IF EXISTS (SELECT * FROM sys.objects WHERE object_id =OBJECT_ID(N'[dbo].[Users]') AND type in (N'U'))

BEGIN

Drop table Users

 

END



 

In this query we are checking table existence before dropping it.

 

We can also check other way around in this query it is also very much simple

 

Query:

 


IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id =OBJECT_ID(N'[dbo].[Login]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Login](

      [UserID] [varchar](50) NOT NULL,

      [Password] [varchar](20) NULL,

      [Type] [varchar](20) NULL,

PRIMARY KEY CLUSTERED

(

      [UserID] ASC

)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

END

 

In this we are creating table after checking that it does not exist.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get all objects in a database using PL-SQL in SQL server 2008.

Disclaimer - Privacy
© 2002-2017 DevASP.net