Dropping tables and dbo

Results 1 to 2 of 2

Thread: Dropping tables and dbo

  1. #1
    Join Date
    Dec 1969

    Default Dropping tables and dbo

    I am trying to drop three tables in an t-SQL stored procedure. <BR>I need to drop the tables because I create these tables within the stored procedure. The problem I am having is that my stored procedure is crashing because it says that the table I am trying to create already exists. Obviously, my drop tables are not working correctly. I am also part of the sysadmin group and hence my dbo prefix should work for dropping any table. Can someone please help?<BR> <BR><BR>If Exists (Select * From sysObjects where Type = &#039;U&#039; And Name = &#039;dbo.Unr_Total_Capital_Invested&#039;) <BR>Begin<BR> Drop Table dbo.Unr_Total_Capital_Invested<BR>End<BR><BR>If Exists(Select * From sysObjects where Type = &#039;U&#039; and Name = &#039;dbo.Realz_Total_Capital_Invested&#039;) <BR>Begin<BR> Drop Table dbo.Realz_Total_Capital_Invested<BR>End<BR><BR>If Exists (Select * From sysObjects where Type = &#039;U&#039; and Name = &#039;dbo.Total_Capital_Invested&#039;) <BR>Begin<BR> Drop Table dbo.Total_Capital_Invested<BR>End<BR><BR>-- The Creation Of The Table is as follows. <BR><BR>Select * Into Total_Capital_Invested <BR> From SomeTable1<BR><BR>Select * Into Unr_Total_Capital_Invested <BR> From SomeTable2<BR><BR>Select * Into Realz_Total_Capital_Invested <BR> From SomeTable3<BR>

  2. #2
    Join Date
    Dec 1969
    Indianapolis, IN

    Default RE: Dropping tables and dbo

    1. If you put some check statements inside your Begin Ends, do they show up? For example:<BR>If Exists (Select * From sysObjects where Type = &#039;U&#039; And Name = &#039;dbo.Unr_Total_Capital_Invested&#039;) <BR>Begin<BR>Print &#039;Dropping Unr_Total_Capital_Invested&#039;<BR>Drop Table dbo.Unr_Total_Capital_Invested<BR>End<BR><BR>2. Have you tried to use the DROP TABLE command without the dbo prefix? You create the tables without it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts