Wednesday, 11 April 2018

How to check if a table is exist or not?

The following are queries to check the object / table exist or not before create / drop in Sql Server.

 IF OBJECT_ID('dbo.temp_data') IS NOT NULL
       BEGIN
            execute (N'DROP TABLE [dbo].[temp_data]')
        END

    IF OBJECT_ID('dbo.temp_data') IS NULL
BEGIN
       CREATE TABLE [dbo].[temp_data](
                [no] [int] NULL,
                [empname] [varchar)100)] NULL,
                [empDept] [varchar(100)] NULL,
                [empLocation] [varchar(100)] NULL
            ) ON [PRIMARY]
        END

No comments:

Post a Comment

How to unlock a locked account in sql server?

You tried to login a user and have this message / error: The account is currently locked out.  Solution: Step 1: Login to sql ser...

Popular