Last active
August 30, 2016 05:14
-
-
Save mz026/167ed89ed66a92e3f338 to your computer and use it in GitHub Desktop.
Postgres create foreign key constraint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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