الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

عندي مشكلة في عملية الريط ولقيت حلها ولكن مافهمت منها شي

بدأه .::ICe-AA::. في 19 يونيو 2011 · 2 رد · 712 مشاهدة · في قواعد بيانات Microsoft SQL Server
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

عندي مشكلة في الريط

دورة لها على حل ولقيت موضوع بنفس مشكلتي بالضبط ولها حل ولكني مافهمت اي شي من الحل

المشكلة كالتالي:

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#

الموضوع منقول من

http://forums.asp.net/t/1331710.aspx

تم تعديل هذه المشاركة بواسطة .::ICe-AA::. في 19 يونيو 2011 في 16:02

#2

9 مشاهدات ولا رد

اذا الموضوع في ال قسم الخطأ ياريت تقولولي

#3
.::ICe-AA::. كتب:

عندي مشكلة في الريط

دورة لها على حل ولقيت موضوع بنفس مشكلتي بالضبط ولها حل ولكني مافهمت اي شي من الحل

المشكلة كالتالي:

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#

الموضوع منقول من

http://forums.asp.net/t/1331710.aspx

انا لم افهم المشكله بشكل مفهوم هل المشكلة فى ربط الجداول ام فى الحفظ

رجاء توضيح المشكلة حتى نستطيع المساعدة

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…