If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Renaming Table Constraints

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-09-11, 12:40
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Renaming Table Constraints

I had to rename a table yesterday due to a contact / group name change in the office and sadly I'm the only person who knows how to barely interact with SQL due to my years as a Linux Administrator. Renaming the table was simple:

Code:
iamunix=# ALTER TABLE accounts RENAME TO marketing;
ALTER TABLE
Simple and easy but now I realize all my table constraints are still named with the old table name.

Code:
iamunix=# \d marketing
          Table "public.marketing"
 Column  |         Type          | Modifiers
---------+-----------------------+-----------
 id      | integer               | not null
 vendor  | character varying(40) | not null
 account | integer               | not null
 email   | character varying(40) | not null
 state   | character(2)          | not null
Indexes:
    "accounts_pkey" PRIMARY KEY, btree (id)
    "accounts_account_key" UNIQUE, btree (account)
    "accounts_email_key" UNIQUE, btree (email)
    "accounts_vendor_key" UNIQUE, btree (vendor)
I've searched the web and can't find any SQL example command to rename them. I don't know if the proper procedure is to remove / recreate the constraints or if there actually is a command to do what I want. I can't be the 1st guy to have to rename a table and match the table constraints for organization. My main confusion is that when I create a table from scratch, it auto creates the indexes you see so I have no idea how to edit the constraint.

I do know how to:

Code:
ALTER TABLE foo ALTER COLUMN color DROP NOT NULL;
I just need help renaming the constraints.
Reply With Quote
  #2 (permalink)  
Old 04-09-11, 17:47
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Code:
ALTER INDEX blah RENAME TO meh;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On