473,404 Members | 2,174 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,404 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 33644
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: 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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.