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.