2
0
mirror of https://github.com/chubin/cheat.sheets synced 2024-11-03 15:40:17 +00:00
cheat.sheets/sheets/_psql/columns

23 lines
603 B
Plaintext
Raw Normal View History

2018-01-07 11:42:08 +00:00
# Add column
ALTER TABLE <table_name> IF EXISTS
ADD <column_name> <data_type> [<constraints>];
# Update column
ALTER TABLE <table_name> IF EXISTS
ALTER <column_name> TYPE <data_type> [<constraints>];
# Delete column
ALTER TABLE <table_name> IF EXISTS
DROP <column_name>;
# Update column to be an auto-incrementing primary key
ALTER TABLE <table_name>
ADD COLUMN <column_name> SERIAL PRIMARY KEY;
# Insert into a table, with an auto-incrementing primary key
INSERT INTO <table_name>
VALUES (DEFAULT, <value1>);
#
INSERT INTO <table_name> (<column1_name>,<column2_name>)
VALUES ( <value1>,<value2> );