简体   繁体   中英

Delete row in sql from table

Sorry for the title but I didn't know how to name it..

I'm using C# and have a WinForms application I have 2 tables, each of them have a primary key, those 2 tables are strangers. It means that I have a third table that connects between them. the third table have as columns : table's A primary key and table's B primary key.

I just want to know that if I'm deleting one row from the third table, is the related data from table A and B will be also deleted?

If you created a foreign key constraint with the ON DELETE CASCADE option, then yes, it will delete the related rows in other tables.

If you created a foreign key constraint WITHOUT the ON DELETE CASCADE option, then the DBMS will prevent you from deleting the original row at all.

If you did not create a foreign key constraint then only the original row will be deleted.

See this SO answer for example usage of the cascading delete option.

No, it doesn't your third table is just associate table which stores references of table A and B.

But it will have different functionality other way, if a record is deleted in table A and it has any references in associate table C. Depending upon your cascade options, record in table C will also be deleted. If there are no cascade options mentioned, it gives exception.

Sql Server wouldn't let you delete the row from 3rd table because of a Foreign Key constraint. You'd have to delete the values referencing the 3rd table from table A and B first and then delete from your 3rd table.

否,因为第三个表是表a和表b的关联表,如果删除在第三个表上,则不会删除表a和表b中的记录。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM