Sam05
Sam05

Reputation: 3

Invalid object name in sql when deleting

This is my procedure:

CREATE PROCEDURE deleteThisCusDetails 
   @customerName nvarchar(50)
AS
BEGIN
    DELETE t1, t2, t3
    from CustomerMainInfo as t1 
    join Location as t2 ON t1.customerID = t2.customerID
    join Room as t3 on t2.locationID = t3.locationID
    WHERE t1.customerName = @customerName
END

While I'm typing it and before executing it a red line shows up under t1 (the first t1 only), which tells that this is an invalid object.

Am I doing something wrong with this delete query? All my tables exist, so why the red line under t1?

Upvotes: 0

Views: 2674

Answers (2)

Azar
Azar

Reputation: 1867

My Frnd you can use cascade upon delete option in SQL server to achieve this.

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172548

Am I doing something wrong with this delete query?

Yes you are doing it wrong. You can not delete the rows using multiple tables. There is no multiple table entry deletion rule in SQL server.

You have to delete it one by one from the table using something like this:

delete from table_name where column_name = 'condition'

Upvotes: 4

Related Questions