Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot drop table because it does not exists

Status
Not open for further replies.

charlize

Programmer
Feb 23, 2005
9
NL
Hi,

I need to copy a couple of tables from one database to another. In my SSIS package I have created a Transfer SQL Server Objects Task. The problem is that some of the tables already exists, but some of them do not. If the table does not exists, then I get an error and the package stops executing. I do not know which tables exists or not. Is there a property that you can set to check if the table exist? Or can I skip the error when the table does not exist?

Charlize
 
When using VS to generate drop/create scripts in one the drop portion is;
Code:
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[YOUR_SCHEMA_NAME].[YOUR_TABLE_NAME]') AND type in (N'U'))
DROP TABLE [YOUR_SCHEMA_NAME].[YOUR_TABLE_NAME]
GO

Essentially it checks for the existance of the table and drops it if it does.

Rhys
The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense Edsgar Dijkstra

Church of the Flying Spaghetti Monster
 
Yes, I know, but I want to delete all tables, views and stored procedures at once before creating them again.
Is that possible? And does anybody know why the option replace (if exists) does not work when using the transfer database objects as control flow?

Charlize
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top