SP for deleting TABLE

Results 1 to 2 of 2

Thread: SP for deleting TABLE

  1. #1
    ED Guest

    Default SP for deleting TABLE

    This is my SP command..<BR><BR>I get syntax error @ DROP TABLE @tbName line.<BR><BR>what&#039;s wrong??<BR><BR>Create Proc Delete_Table<BR><BR> @tbName varchar(30)<BR><BR>As<BR>Begin<BR><BR> Begin Tran<BR><BR> Drop Table @tbName<BR><BR> Delete from MasterTable where tablename = @tbName<BR><BR> If ( @@error &#060;&#062; 0 ) <BR> RollBack Tran<BR> else<BR> Commit Tran<BR>End

  2. #2
    Join Date
    Dec 1969

    Default Cannot do it this way...

    ...You can&#039;t reference objects as variables. But, you can store the SQL in a string and execute the string.<BR><BR> DECLARE sSQL nvarchar(100)<BR><BR> Select @sSQL = &#039;drop table &#039; + @table<BR> Execute(@sSQL)

Posting Permissions

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