for MS SQL 2000
I am trying to do a hierarchical table and i want to add a ON DELETE CASCADE
CREATE TABLE [dbo].[Users](
[id_Users] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED,
[id_UsersSup] [int] NULL,
[Users] [nvarchar] (100) NOT NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[Users] ADD
CONSTRAINT [FK_Users_Sup] FOREIGN KEY
(
[id_UsersSup]
) REFERENCES [Users] (
[id_Users]
)
ON DELETE CASCADE
but MS SQL refuse to create the foreign key
even if there is 4 levels under the deleted id_Users I want to delete all the rows on all levels under
thank you for helpingI tried running your code on SQL Server 2005, and got the following message:
Introducing FOREIGN KEY constraint 'FK_Users_Sup' on table 'Users' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
In my opinion, this error message tells pretty well why you are not allowed to use on delete cascade on a self-join.|||You will need to implement this cascading referential integrity using a trigger.
Showing posts with label identity. Show all posts
Showing posts with label identity. Show all posts
Friday, March 23, 2012
Monday, February 20, 2012
Old, deleted Identity values re-used?
If I have an Identity-declared column, the table has lots of rows and I start deleteting records - will any old, deleted identities be re-used (without an explicit re-seed) ?
(I'm talking about numerical Identities, not these GUID things)No. Not without manipulating the IDENTITY column. The exception being that if you TRUNCATE the table, then the seed will reset to the floor value.
Regards,
hmscott|||yeah,it can be used
need to set identity off
insert statement
reset identity on
(I'm talking about numerical Identities, not these GUID things)No. Not without manipulating the IDENTITY column. The exception being that if you TRUNCATE the table, then the seed will reset to the floor value.
Regards,
hmscott|||yeah,it can be used
need to set identity off
insert statement
reset identity on
Subscribe to:
Posts (Atom)