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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropping tables

Status
Not open for further replies.

suhash

Programmer
Joined
Aug 15, 2005
Messages
10
Location
GB
Hi Again,

I need to drop a table and create a new one on a trigger.

CREATE TRIGGER TBL_DEL ON dbo.PeerFileListCollection
FOR DELETE
AS
DECLARE @RecordRemoved nvarchar(10)
Declare @TableName nvarchar(10)
declare @SQL nvarchar(100)
Select @RecordRemoved = (Select PeerID From deleted)
set @SQL = ' DROP TABLE ' + 'dbo.'+ltrim(@RecordRemoved)
EXEC(@SQL)

I am using the above code to delete a table, but it is throwing an error. I have tried without "dbo." as well. Still the same.

Thanks in advance

Mal.
 
Hi.

The error is like:

Syntax error near 12.

12 is the name of the table..

Thanks,,
 
Table names normally cannot begin with numeric character... have you tried wrapping name into [] ?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Hi..

Yep, u are correct, Sorted the problem out.

Thanks for your time..

Mal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top