473,414 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Referetial Integrity - set default, null

144 100+
hi,

can i set that, when the primary-key in a parent table is updated or deleted, the foreign-key in the child table will be set to its default value.

i've tried using the following command
Expand|Select|Wrap|Line Numbers
  1. FOREIGN KEY (kdJur) REFERENCES parent ON UPDATE set default,on delete set null
but, i receive this error
Incorrect syntax near the keyword 'set'.


is there any way to achieve this?

thank you.
Oct 15 '08 #1
2 1374
ck9663
2,878 Expert 2GB
I'm not sure you can do that command. There are only two options on that can be used for the ON UPDATE clause. Here's the complete syntax (search for ON UPDATE). You either take NO ACTION or CASCADE.

Here's an extract from BOL

If CASCADE is specified, the row is updated in the referencing table if that row is updated in the parent table. If NO ACTION is specified, SQL Server raises an error and the update action on the row in the parent table is rolled back.


But it still can be done.

Create an INSTEAD OF trigger to do the CASCADING update for you. The cascade, in this case, will replace the value of your Foreign Key to NULL instead of a CASCADE update or a CASCADE delete.

Just a thought, I'm not sure how your app works, but this will result in a lot of what we call "orphan records".

Happy coding!

-- CK
Oct 15 '08 #2
thesti
144 100+
hi ck9663,

thanks for the reply. it helps!
Oct 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: obhayes | last post by:
Hi, I have two tables Table A and B, below with some dummy data... Table A (contains specific unique settings that can be requested) Id, SettingName 1, weight 2, length Table B (contains...
0
by: Sharon Cowling | last post by:
Hi, my problem is this: I have a table called faps_key the unique identifier being key_code: taupo=# \d faps_key Table "faps_key" Column | Type | Modifiers...
7
by: Mike Mascari | last post by:
Hello. I have time-varying relation variables similar to the ones described in this Rick Snodgrass article: http://www.informix.com.ua/articles/tempref/tempref.htm An example: CREATE...
4
by: aj | last post by:
DB2 v8 FP5 WSE LUW Red Hat Linux 2.1AS I'm like to add a new column to an existing table that will be NOT NULL and have a WITH DEFAULT value. The table has a huge assortment of triggers,...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
7
by: Jimmie H. Apsey | last post by:
Referential Integrity on one of our production tables seems to have been lost. I am running Postgres 7.1.3 embedded within Red Hat kernel-2.4.9-e.49. Within that I have a table with referential...
6
by: Jeff North | last post by:
I'm using Microsoft SQL Server Management Studio Express 9.00.2047.00 and expriencing problems with setting referential integrity on a link table. The tables' schema is as follows:...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
2
by: njames | last post by:
There are two doubts regarding integrity constraints : 1) Can the constraints "NOT NULL" and "DEFAULT" be assigned at table level ? i have tried using the syntax of CHECK constraint at table...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.