tags:

views:

42

answers:

2

I have two tables in my database and the t1 table primary key is uid, t2 table a foreign key name desg. now I want to delete or update this uid in one table give error that

Now row was updated. data in the row was not committed. error source:.netSqlclient data provider. error message: the update statement conflicted with the reference constraint fk_t2_t1.the conflict occur in the database DBname, dbo.t2,column desg. the stsement has been terminated.

and when I try to delete, it show this message.

executed SQl statement: delete from t1 where uid='abc'

error source:.netSqlclient data provider. error message: the Delete statement conflicted with the reference constraint fk_t2_t1.the conflict occur in the database DBname, dbo.t2,column desg. the stsement has been terminated.

Please tell me how to do this update and delete.

I am new to this field need help thanks in advances.

+2  A: 

first delete the t2 table a foreign key then delete t1 table primary key is uid . this will work not vise versa

anishmarokey
+1  A: 

You have one or more child records in table t2 which are pointing at the master record in table t1 that you want to delete. Before you can delete your record in t1, you must delete the child records in t2.

For example:

(1) delete * from t2 where t2.desg = t1.uid;

(2) delete * from t1 where t1.uid = UID_TO_BE_REMOVED;

I would recommend reading a good reference on creating tables and performing queries for the SQL database you are using.

Good luck!

Winger
+1: Precisely. `CASCADE DELETE` would've allowed a deletion on the parent to sync the children, but it's risky because it allows wholesale deletions.
OMG Ponies
Don't tell this to novices
vgv8
hi thanks for u guideline,is there any way to do this in one line query