عندي مشكلة في الريط
دورة لها على حل ولقيت موضوع بنفس مشكلتي بالضبط ولها حل ولكني مافهمت اي شي من الحل
المشكلة كالتالي:
Users:
-ID
-Username
-Password
and
Messages:
-ID
-From
-To
-Subject
-Body
-isRead
-Date
-Sender
-Receiver
And i want to set relations like:
1. Messages.From -> Users.ID
Delete Rule: Set Null
Update Rule: No Action
2. Messages.To -> Users.ID
Delete Rule: Set Null
Update Rule: No Action
But it gives an error when i want to save:
'Users' table saved successfully
'Messages' table
- Unable to create relationship 'FK_Messages_Users_From'.
Introducing FOREIGN KEY constraint 'FK_Messages_Users_From' on table 'Messages' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint. See previous errors.
What does it mean? Why it happens?
الحل الغير مفهوم لهذه المشكلة هو كالتالي:
Oct 11, 2008 12:53 PM
Something like this works. Note: This may not be a problem but...if you delete the sender and receiver of messages, the message will be "Orphaned".
USE [Test]
GO
/****** Object: Trigger [dbo].[SetMsgUserIDsToNull] Script Date: 10/11/2008 07:51:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE TRIGGER [dbo].[SetMsgUserIDsToNull]
ON [dbo].[Users]
AFTER Delete
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
declare @UserID as int;
set @UserID = (select ID from Deleted);
Update Messages set FromID = NULL where FromID = @UserID;
Update Messages set ToID = NULL where ToID = @UserID;
ENDللمعلومية انا استخدك ASP.NET with C#
الموضوع منقول من