I made tables using SQL Server DBMS, I know that there is ON DELETE CASCADE, but I don’t know how to put it in the SQL server. How can I create a query using the inner join to remove related records from 3 tables? Here is my database, you need to delete the string "group number" from the "Groups" table. Thanks in advance!
|
1 answer
In SQL-server, it is not possible to delete records from several tables with a single query. You will have to use several queries:
delete from [Журнал] where [номер_студента] IN( select [номер_студента] from [Студенты] where [Номер_группы]=XX ); delete from [Студенты] where [Номер_группы]=XX; delete from [Группы] where [Номер_группы]=XX; But it’s much better to remake foreign keys and use ON DELETE CASCADE . For this, the keys will most likely need to be re-created. Those. delete them with the alter table X drop constraint Y and recreate them with the alter table X add constraint Y foreign key ... on delete cascade
|
