473,498 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

integrity constraints problem

8 New Member
I am trying to create my tables where if i delete/update a record from one table, all the other tables are affected by deleting/updating any records that reference the original record.

For example, if i delete/update a record from the employee table, the other tables that are referenced to it will be updated/deleted

Here is the database create SQL i have

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE Employee (
  2.   ssn             NUMBER (4) PRIMARY KEY,
  3.   salary          NUMBER (5),
  4.   phone          NUMBER (11)
  5.   );
  6.  
  7. CREATE TABLE Department (
  8.   dno          NUMBER (1) PRIMARY KEY,
  9.   dname          VARCHAR2 (20),
  10.   budget      NUMBER (6)
  11.   );
  12.  
  13. CREATE TABLE Child (
  14.   name            VARCHAR2 (20) UNIQUE,
  15.   age          NUMBER (2),
  16.   check(age BETWEEN 0 AND 18)
  17.   );    
  18.  
  19. CREATE TABLE Children (
  20.   ssn          NUMBER (4),
  21.   name          VARCHAR2 (20),
  22.   CONSTRAINT emp_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL ON UPDATE CASCADE,
  23.   CONSTRAINT chd_FK FOREIGN KEY(name) references Child(name) ON DELETE SET NULL ON UPDATE CASCADE
  24.   );
  25.  
  26. CREATE TABLE Works (
  27.   ssn          NUMBER (4),
  28.   dno          NUMBER (1),
  29.   CONSTRAINT empl_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL ON UPDATE CASCADE, 
  30.   CONSTRAINT dept_FK FOREIGN KEY(dno) references Department(dno) ON DELETE SET NULL ON UPDATE CASCADE 
  31.   );
  32.  
  33. CREATE TABLE Manages (
  34.   ssn          NUMBER (4),
  35.   dno          NUMBER (1),
  36.   CONSTRAINT employ_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL ON UPDATE CASCADE, 
  37.   CONSTRAINT depart_FK FOREIGN KEY(dno) references Department(dno) ON DELETE SET NULL ON UPDATE CASCADE 
  38.   );
  39.  
  40. CREATE TABLE NewMember (
  41.   ssn          NUMBER (4),
  42.   dno           NUMBER (1)
  43.   );
When i try to run the code I get this error

ORA-00907: missing right parenthesis
and it points to these lines

Expand|Select|Wrap|Line Numbers
  1. CONSTRAINT emp_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL ON UPDATE CASCADE,
  2. CONSTRAINT empl_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL ON UPDATE CASCADE
  3. CONSTRAINT employ_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL ON UPDATE CASCADE
It seems strange that the other foreign keys aren't affected and i don't know if they will when i fix this problem
Nov 24 '07 #1
4 3968
amitpatel66
2,367 Recognized Expert Top Contributor
Try this:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE Children (
  2.   ssn          NUMBER (4),
  3.   name          VARCHAR2 (20),
  4.   CONSTRAINT emp_FK FOREIGN KEY(ssn) references Employee(ssn) ON DELETE SET NULL,
  5.   CONSTRAINT chd_FK FOREIGN KEY(name) references Child(name) ON DELETE SET NULL 
  6.   );
  7.  
Try the same for all other CREATE table statements as well
Nov 25 '07 #2
Adrock952
8 New Member
I figured it out last night. It turns out that Oracle doesn't have an ON UPDATE constraint so i deleted that and it worked
Nov 25 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
I figured it out last night. It turns out that Oracle doesn't have an ON UPDATE constraint so i deleted that and it worked
Yes thats right. but you can achieve this by creating user defined procedures and a trigger to achieve this functionality!!
Nov 26 '07 #4
rallen
1 New Member
Yes thats right. but you can achieve this by creating user defined procedures and a trigger to achieve this functionality!!

You can also use dbConstructor to create your scripts and it will automatically generate the declarative and trigger referential constrain.

Regards,

Robert Allen Schambach
Nov 28 '07 #5

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

Similar topics

9
1423
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...
4
15793
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
6
2031
by: Christian Rank | last post by:
Hello, I came across the following problem with integrity constraints and PL/pgSQL (PostgreSQL version used: 7.4.2): I defined the following tables, constraints and data: create table a (n...
1
3645
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...
6
2474
by: Greg Stark | last post by:
There's another poster complaining about referential integrity checks causing deadlocks. Unfortunately I've deleted the message so this response (and the archives aren't responding) isn't going to...
7
2436
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
4933
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:...
80
7791
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used...
3
2104
by: shsandeep | last post by:
In a data warehousing application, what is the impact of imposing referential integrity on the database side? Does it help or degrade the performance considering the complex transformations that...
2
1363
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
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
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...
1
6885
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
5462
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,...
1
4908
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...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.