Skip to content

Instantly share code, notes, and snippets.

@mz026
Last active August 30, 2016 05:14
Show Gist options
  • Save mz026/167ed89ed66a92e3f338 to your computer and use it in GitHub Desktop.
Save mz026/167ed89ed66a92e3f338 to your computer and use it in GitHub Desktop.
Postgres create foreign key constraint
# add foreign key constraint
execute <<-SQL
alter table access_tokens
add constraint fk_access_token_user_id
foreign key (user_id)
references users(id)
on delete cascade
SQL
# add unique index
execute <<-SQL
CREATE UNIQUE INDEX <index_name>
ON <table> (<col1>, <col2>)
SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment