Search
 
SCRIPT & CODE EXAMPLE
 

SQL

postgresql create table many-to-many

CREATE TABLE product (
  product_id serial PRIMARY KEY  -- implicit primary key constraint
, product    text NOT NULL
, price      numeric NOT NULL DEFAULT 0
);

CREATE TABLE bill (
  bill_id  serial PRIMARY KEY
, bill     text NOT NULL
, billdate date NOT NULL DEFAULT CURRENT_DATE
);

CREATE TABLE bill_product (
  bill_id    int REFERENCES bill (bill_id) ON UPDATE CASCADE ON DELETE CASCADE
, product_id int REFERENCES product (product_id) ON UPDATE CASCADE
, amount     numeric NOT NULL DEFAULT 1
, CONSTRAINT bill_product_pkey PRIMARY KEY (bill_id, product_id)  -- explicit pk
);
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql where in maintain order group_concat 
Sql :: oracle grant directory 
Sql :: mysql join two tables 
Sql :: how to find top 3 salary in sql 
Sql :: delete all duplicate rows keep the latest except for one in mysql 
Sql :: sqlite unix timestamp 
Sql :: oracle alter table add column 
Sql :: sql row having max 
Sql :: mysql default uuid 
Sql :: mysql server not running 
Sql :: mariadb create index if not exists 
Sql :: get stored procedure text sql server 
Sql :: insert into postgres 
Sql :: insert to postgres table 
Sql :: sql cheat sheet 
Sql :: drop procedure if exists sql server 
Sql :: while in sql server 
Sql :: enum in sql server 
Sql :: having clause 
Sql :: sql table alias join 
Sql :: set engine to innodb 
Sql :: union syntax in oracle 
Sql :: mysql bind-address default value 
Sql :: desinstaller mysql sur ubuntu definitivement 
Sql :: sql server whoami 
Sql :: excel vba import data to sql server 
Sql :: mysql row generator 
Sql :: DIFFERENCE BETWEEN 2 COLN IN SQL 
Sql :: postgresql alter column data type from integer to integer array 
Sql :: Pl/Sql table based record 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =