Question: I am a novice web application developer and I am learning by developing a web app where each successfully registered user will login to his database. all the users have **the same database schema** and there comes a time where I need to update the schema because of a feature I've added.

I am trying to find away to update all the databases (PostgreSQL) with a new schema in one single command in the Package Manager Console of Visual Studio. 

My normal approach is that I create a migration (my new schema) with the following command:

> 
> add-migration -context MyContextRecords initial
> 
> 
> 

then the next command which I do is:

> 
> update-database -context MyContextRecords
> 
> 
> 

The second command works with one database at a time that I specify in my class and I have to drop and delete the database before typing this command, doing so means that all data is lost that the user stored. not to mention if I have 100 of users.... doing this command one at time for each registered user isn't convenient at all... so I am sure there must be a better way?!?!?

So, is there a better approach in the Package Manager Console to be able to update all the databases schema for all the users, without Drop/Delete (pgAdmin) and lose data. 

Thanks :)

Answer: 
> 
> I need to delete rows from both tables if A.itemID does not exist in table B
> 
> 
> 

If the `itemId` does not match, then there is no row in `B`. So, you just need to delete in `A`. So:

```
DELETE a FROM a
    WHERE NOT EXISTS (SELECT 1
                      FROM B b
                      WHERE b.cid = a.itemID
                     );

```
You could also express your logic using a delete anti-join:

```
DELETE a
FROM A a
LEFT JOIN B b ON b.cid = a.itemID
WHERE b.cid IS NULL;

```