Avatar of blossompark
blossompark
Flag for Ireland asked on

dropping a table if it exists in sql server 2005

Hi,
    The following code  creates a table called New_Table in the database
and loads the result of the UNION into the new table.

SELECT  X.* INTO New_Table FROM

((SELECT  
 Netbios_name as Machine_Name,
Last_Login as User_Name
FROM  Table_A)

union

(select
CI_Name,
Used_by
from
Table_2)) as X


I now need to drop this table if it exists ,
my question is what syntax do i need to precede this with in order to drop the table New_Table?

Thanks
Microsoft SQL Server 2005SQL

Avatar of undefined
Last Comment
blossompark

8/22/2022 - Mon
SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Lee

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
tolgaong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Pratima

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Pratima

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
blossompark

ASKER
hi ryancys, thanks for input...didn't try this ...

hi lsavidge, thanks for your additional comment

Hi togaong,
if object_id('New_Table') is not null
   Drop TABLE New_Table
worked fine...thanks... have not used temp table option

hi pratima mcs...those options didn't work for me ,....thanks for the inputs
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23