Skip to content

Instantly share code, notes, and snippets.

View nix1947's full-sized avatar
:octocat:
Pro

Manoj Gautam nix1947

:octocat:
Pro
View GitHub Profile
@nix1947
nix1947 / gist:dc68cd741c3bb4cb6068220bf0c61c31
Created September 23, 2021 01:49
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)
@nix1947
nix1947 / gist:56e66d1b9d9043e7366ec5f452f64baf
Created September 23, 2021 01:51
unique column with multiple column in mysql. (Useful for one to one relation)
-- One to one relation between user_order and shipping_address table.
create table user_order ADD UNIQUE index("id", "shipping_address_id");