Delete a record in two tables in one SQL query

I have two tables

EMPGROUP_TBL
SEQID | MASTERID | BUSINESS_UNIT | DIVISION | SUB_DIVISION | CLASSIFICATION | SUB_CLASSIFICATION

and

EMP_MASTERTBL
MASTERID | EMPNO | LASTNAME | FIRSTNAME | JOBTITLE | LOCATION |

In my table in ASP.NET JOBTITLE, BUSINESS_UNIT, DIVISION, SUB_DIVISION, CLASSIFICATION and SUB_CLASSIFICATION together.

So, when I need to delete an entry in girdview, I need to delete the JOBTITLE in EMP_MASTERTBL and the entire entry in EMPGROUP_TBL.

This is my code.

DELETE em.JOBTITLE, eg.BUSINESS_UNIT, eg.DIVISION, eg.SUB_DIVISION, eg.CLASIFFICATION, eg.SUB_CLASSIFICATION
FROM EMP_MASTERTBL AS em, EMPGROUP_TBL AS eg
WHERE em.MASTERID = eg.MASTERID AND eg.MASTERID = '76196'

Every time I run or execute my code there, this is an error Incorrect syntax near ','.

I tried using a different approach for my code, but it's still the same.

I also tried this

DELETE JOBTITLE FROM EMP_MASTERTBL WHERE MASTERID = '76196';
DELETE FROM EMPGROUP_TBL WHERE MASTERID = '76196'

But I got an error Invalid object name 'JOBTITLE'..

What could be the problem? Thank.

+4
source share
1 answer

, , . , delete, .

, EMP_MASTERTBL EMPGROUP_TB. http://www.mysqltutorial.org/mysql-on-delete-cascade/

Edit

, , :

UPDATE EMP_MASTERTBL
   SET JOBTITLE = NULL
   WHERE MASTERID = '76196';

DELETE FROM EMPGROUP_TB
   WHERE MASTERID = '76196';

JOBTITLE NULL EMPGROUP_TB.

+2

Source: https://habr.com/ru/post/1661541/


All Articles