mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 00:58:02 +00:00
Add Renaming A Table as a postgres til
This commit is contained in:
@@ -193,6 +193,7 @@ _369 TILs and counting..._
|
||||
- [Max Identifier Length Is 63 Bytes](postgres/max-identifier-length-is-63-bytes.md)
|
||||
- [pg Prefix Is Reserved For System Schemas](postgres/pg-prefix-is-reserved-for-system-schemas.md)
|
||||
- [Pretty Print Data Sizes](postgres/pretty-print-data-sizes.md)
|
||||
- [Renaming A Table](postgres/renaming-a-table.md)
|
||||
- [Restart A Sequence](postgres/restart-a-sequence.md)
|
||||
- [Restarting Sequences When Truncating Tables](postgres/restarting-sequences-when-truncating-tables.md)
|
||||
- [Salt And Hash A Password With pgcrypto](postgres/salt-and-hash-a-password-with-pgcrypto.md)
|
||||
|
||||
22
postgres/renaming-a-table.md
Normal file
22
postgres/renaming-a-table.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# Renaming A Table
|
||||
|
||||
Using the `alter table` command in PostgreSQL, you can rename an existing
|
||||
table. This command will also update any references to the table such as via
|
||||
foreign key constraints. Just run a command like the following:
|
||||
|
||||
```
|
||||
alter table ingredient_types rename to item_types;
|
||||
```
|
||||
|
||||
Note that this may result in breaking a number of conventions. Foreign keys,
|
||||
sequences, and constraints with names eponymous to the original table will
|
||||
no longer follow convention despite the references being updated. These can
|
||||
be renamed as well if desired.
|
||||
|
||||
See
|
||||
[`renaming_table.sql`](https://github.com/jbranchaud/postgresing/blob/master/renaming/rename_table.sql)
|
||||
for a full example.
|
||||
|
||||
See the [`alter table`
|
||||
docs](http://www.postgresql.org/docs/current/static/sql-altertable.html) for
|
||||
more details.
|
||||
Reference in New Issue
Block a user