Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need Help- delete from tableA where not in tableB

Author  Topic 

fulgar125
Starting Member

1 Post

Posted - 2011-05-02 : 10:38:58
Hey,

Im fairly new to SQL and i have made a mess up my DotNetNuke database. I have deleted records from dbo.Users table, only to find out.. i need to also delete the matching records from the dbo.aspnet_Membership & dbp.aspnet_Users tables.

What im trying to do is delete the records from the other two tables by comparing the two tables and deleting all the records that dont have a match.

My SQL goes something like this..

DELETE FROM dbo.aspnet_Membership
where Email not in (
Select Email from dbo.Users)

I want to compare and delete using the email field because both tables have those records.

However, i get an error saying 'Changed database context to 'dotNetNuke'.

Can anybody help me with this?

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-02 : 12:11:25
--DELETE am
SELECT *
FROM aspnet_Membership am
WHERE NOT EXISTS (SELECT * FROM Users u WHERE am.Email = u.Email)


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -