Skip to content

Instantly share code, notes, and snippets.

@nix1947
Created September 23, 2021 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nix1947/dc68cd741c3bb4cb6068220bf0c61c31 to your computer and use it in GitHub Desktop.
Save nix1947/dc68cd741c3bb4cb6068220bf0c61c31 to your computer and use it in GitHub Desktop.
Creating a foreign key table in mysql with references.
-- Creating a table with foreign key references.
create table user_order(
id int not null PRIMARY key AUTO_INCREMENT,
user_id int not null,
shipping_address_id int not null,
order_date timestamp DEFAULT CURRENT_TIMESTAMP,
total_quantity int not null,
total_price int not null,
FOREIGN KEY (user_id) REFERENCES user(id),
FOREIGN KEY (shipping_address_id) REFERENCES shipping_address(id)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment