Microsoft
Software
Hardware
Network
Question : Setting Primary Key Clustered with foriegn Key cascade - SQL
I havent done any DBA in two years and I am rusteee...
The scenario is - we have added a custom rolesinroles table that consists of RoleId and Parent RoleId - I am trying to do the following, which may be quite simple
Create a Primary clustered key from both of the Ids - is this correct ?
/****** Object: Index [PK__RolesInRoles__1B29035
F] Script Date: 07/19/2010 22:14:18 ******/
ALTER TABLE [dbo].[RolesInRoles] ADD PRIMARY KEY CLUSTERED
(
[RoleId] ASC,
[ParentRoleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
I would like both the RoleId and ParentRoleId to reference another table's primary Key "Roles", and do a cascading delete when that "Role" is deleted if the ParentRoleId = Role.RoleId
or if RoleId = Role.RoleId
Any help is greatly appreciated
Also, while I have your ear - if I try to add a duplicate of the clustered key, is there an elegant way to catch it ?
Thanks!
Answer : Setting Primary Key Clustered with foriegn Key cascade - SQL
>> if I try to add a duplicate of the clustered key, is there an elegant way to catch it ?
You could always create INSTEAD OF INSERT/UPDATE triggers and catch the duplicate (non-trivial) and provide a more friendly message or fail silently.
Random Solutions
How do I use the Windows XP installation disc to replace missing system files?
Javascript to get <TD> inner text in MSIE, FF and Chrome
Out of Office Assistant not working w/Forwarding Configured
How to get lightbox to show over Flash banner?
Strip out ’s in mySQL query | XML Parsing Error: undefined entity
Net Use returns "System error 64 has occurred. The specified network name is no longer available."
How can I dynamically switch web service addresses in .NET without a recompile?
WRT54G2 Linksys router - reset password saving actual configuration
Mail delivery has failed
Adobe - monitor profile [..] appears to be defective. Please rerun your monitor calibration software