473,396 Members | 2,020 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,396 software developers and data experts.

adding on delete cascade constraint?

Currently I have a table defined as such:

TAL=# \d internal_keywords
Table "public.internal_keywords"
Column | Type | Modifiers
---------+---------+-----------
keyword | text | not null
pid | integer | not null
Indexes: internal_keywords_pkey primary key btree (keyword, pid)
Foreign Key constraints: $1 FOREIGN KEY (pid) REFERENCES products(id) ON
UPDATE NO ACTION ON DELETE NO ACTION

How can I change the ON DELETE action to CASCADE for column pid?

I've check the alter table documentation but cannot find any reference
to this.

Thanks,

Jean-Christian Imbeault
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #1
4 33643
On Fri, 2003-09-19 at 11:09, Jean-Christian Imbeault wrote:
Currently I have a table defined as such:

TAL=# \d internal_keywords
Table "public.internal_keywords"
Column | Type | Modifiers
---------+---------+-----------
keyword | text | not null
pid | integer | not null
Indexes: internal_keywords_pkey primary key btree (keyword, pid)
Foreign Key constraints: $1 FOREIGN KEY (pid) REFERENCES products(id) ON
UPDATE NO ACTION ON DELETE NO ACTION

How can I change the ON DELETE action to CASCADE for column pid?

I've check the alter table documentation but cannot find any reference
to this.


Drop the constraint; then add an amended one.

--
Oliver Elphick Ol************@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Bring ye all the tithes into the storehouse, that
there may be meat in mine house, and prove me now
herewith, saith the LORD of hosts, if I will not open
you the windows of heaven, and pour you out a
blessing, that there shall not be room enough to
receive it." Malachi 3:10
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #2
Oliver Elphick wrote:
Foreign Key constraints: $1 FOREIGN KEY (pid) REFERENCES products(id) ON
UPDATE NO ACTION ON DELETE NO ACTION


Drop the constraint; then add an amended one.


Ok, how do I drop the constraint, it has no name.

The documentation is rather poor on how to get the name of unamed
constraints:

"To remove a constraint you need to know its name. If you gave it a name
then that's easy. Otherwise the system assigned a generated name, which
you need to find out. The psql command \d tablename can be helpful here"

Secondly what is the correct syntax for adding a new constraint with ON
DELETE CASCADE?

Thanks,

Jean-Christian Imbeault

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #3
On Fri, 2003-09-19 at 14:02, Jean-Christian Imbeault wrote:
Oliver Elphick wrote:
Foreign Key constraints: $1 FOREIGN KEY (pid) REFERENCES products(id) ON
UPDATE NO ACTION ON DELETE NO ACTION
Drop the constraint; then add an amended one.


Ok, how do I drop the constraint, it has no name.

From what you quoted above, its name is $1
ALTER TABLE xxx DROP CONSTRAINT "$1"; -- double quotes required since
-- $1 is an identifier
Secondly what is the correct syntax for adding a new constraint with ON
DELETE CASCADE?


ALTER TABLE xxx ADD CONSTRAINT "$1" FOREIGN KEY (pid) REFERENCES
products(id) ON UPDATE NO ACTION ON DELETE CASCADE;

--
Oliver Elphick Ol************@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Bring ye all the tithes into the storehouse, that
there may be meat in mine house, and prove me now
herewith, saith the LORD of hosts, if I will not open
you the windows of heaven, and pour you out a
blessing, that there shall not be room enough to
receive it." Malachi 3:10
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 11 '05 #4
On Friday 19 September 2003 14:02, Jean-Christian Imbeault wrote:
Oliver Elphick wrote:
Foreign Key constraints: $1 FOREIGN KEY (pid) REFERENCES products(id) ON
UPDATE NO ACTION ON DELETE NO ACTION
Drop the constraint; then add an amended one.


Ok, how do I drop the constraint, it has no name.


Its name is "$1" - use

DROP CONSTRAINT "$1" ...
Secondly what is the correct syntax for adding a new constraint with ON
DELETE CASCADE?


See the SQL command reference for ALTER TABLE. It's something like:

ALTER TABLE mytable ADD CONSTRAINT constraint_name FOREIGN KEY ... etc

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
0
by: Rob Panosh | last post by:
Hello, If I have table the following table structure: Table Customer ( CustomerId Numeric(10,0) Not Null, ... ) Table CustomerOrders ( CustomerOrderId As Numeric(10,0) Not Null,...
2
by: P.B. via SQLMonster.com | last post by:
I cannot execute my sql to create a table with ON DELETE CASCADE option. Here is my sql: CREATE TABLE Employees (Name Text(10) not null, Age number, CONSTRAINT pkEmployees PRIMARY KEY (Name)); ...
0
by: Partha | last post by:
Here is the script which generates drop and add fkey constraint This is based on another posting << Erland posted this a short time ago, you should be able to modify it to meet your needs:...
3
by: hilz | last post by:
Hi all I am trying to create a relation between two tables. this is the sql statement in question alter table T1 add constraint relation_T1_to_T2 foreign key (T2_ID) references T2 (ID) on...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
2
by: nekiv90 | last post by:
Greetings, I have to delete older policies and its related records in other tables. The deletion from the parent table will trigger the deletion of relevant records from about 30 something...
2
by: manjuns | last post by:
create table A(a1 varchar(10)) create table B(b1 varchar(10), a1 varchar(10) not null) alter table A add primary key(a1) alter table B ADD CONSTRAINT "a_fkey" foreign key (a1) references A (a1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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.