I am having 2 tables :
products :
product_id (PK, int, not null)
reports_id (FK, int, not null)
name
reports :
reports_id (PK, int , not null)
dateR
If I : DELETE FROM reports WHERE reports_id = 100
how can I create a contraints in MS SQL 2000 that automaticly all the products with reports_id = 100 are deleted too ?
thank youChecked the "Cascade Delete Related Records" From Relationship|||but how can I do it as a script (FROM outside)
ALTER TABLE ... CONTRAINST ... ?
thank you|||Check this...
ALTER TABLE products WITH NOCHECK
ADD CONSTRAINT exd_check FOREIGN KEY
(
[reports_id]
) REFERENCES [reports] (
[reports_id]
) ON DELETE CASCADE|||thank you rudra !|||Rudra I am having a probleme the fields are not declared as FK in the database ( I have not created that database) can I use a ON DELETE CASCADE anyway on 2 similar fields ?
something like
ALTER TABLE products WITH NOCHECK
ADD CONSTRAINT exd_check ???
(
[reports_id]
) REFERENCES [reports] (
[reports_id]
) ON DELETE CASCADE
thank you|||why don't you create a on-delete trigger for this?|||i dont know how to do it and i run the commands from a .NET application|||Why are you trying to do this from a user interface? The job of writing triggers belongs to the developer, not the application.|||i want to put it in any way in the database no matter the way|||A trigger is a permanent database object. An application has no business creating such things on the fly.
Either create the trigger or don't, but don't ask us to help you shoot yourself in the foot.
If you insist upon handling relational integrity within the interface, then make two calls to the database. One to delete the child records, and one to delete the parent record.|||thank you for the trigger, and helping me for database code
for the rest i never worry for what i cannot change
Tuesday, February 14, 2012
DELETE on FK
Labels:
database,
daterif,
delete,
int,
microsoft,
mysql,
namereports,
null,
oracle,
product_id,
products,
reports_id,
server,
sql,
tables
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment