This topic is locked
[SOLVED]

 SQL Foreign Key - deleting problem

10/24/2011 9:29:03 AM
PHPRunner General questions
M
marimach77 author

Hello,
I have a problem with SQL foreign key. There are two SQL tables MASTER and SLAVE. Foreign Key is configured for MASTER table, field UserLogin. SLAVE table contains field UserLogin and few other fields. How it should work? If any record in MASTER table has assigned UserLogin which exists in SLAVE table, I should not be able to delete this user record from SLAVE table. It works fine in SQL Enterprise Manager but does not work on web page. When I mark a user record from SLAVE table and click delete selected record, nothing happend, I only see "loading..." message in popup small window. I also see error in IE status bar:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E; InfoPath.2)

Timestamp: Mon, 24 Oct 2011 13:21:36 UTC
Message: Exception thrown and not caught

Line: 2

Char: 15120

Code: 0

URI: http://plwafps01/ccedb/include/loadfirst.js


When I remove FK from SQL table, it works fine on web page. Any idea what could be wrong?
FK has been created using command:

ALTER TABLE [dbo].[MASTER] WITH CHECK ADD CONSTRAINT [MASTER_SLAVE_fk] FOREIGN KEY([UserLogin]) REFERENCES [dbo].[SLAVE] ([UserLogin])


Brgds

Mariusz

C
cgphp 10/24/2011

Is the SLAVE table the MASTER of another table ? Try to disable (not to drop) the foreign key constraint:

ALTER TABLE dbo.slave_table_name NOCHECK CONSTRAINT slave_constraint_fk;
M
marimach77 author 10/25/2011

Is the SLAVE table the MASTER of another table ?



No, it isn't. SLAVE table is always slave for other tables.

Try to disable (not to drop) the foreign key constraint:

ALTER TABLE dbo.slave_table_name NOCHECK CONSTRAINT slave_constraint_fk;




My SLAVE table does not contain any constraint.

M
marimach77 author 10/25/2011

Is there another way to get this functionality without SQL FK and constraints? Any PHP events code?