1ALTER TABLE tblA ADD COLUMN colA VARCHAR(10); /* 1st add column */
2ALTER TABLE tblA ADD CONSTRAINT colA /* Make colA on tblA a foreign key */
3FOREIGN KEY (colA) REFERENCES tblB (colB); /* colB must be a pk on tblB*/
1CREATE TABLE so_items (
2 so_id INTEGER,
3 ...
4 FOREIGN KEY (so_id) REFERENCES so_headers (id)
5);
1UPDATE student
2SET name = institute.inst_name
3FROM institute
4WHERE student.student_id = institute.inst_id;
1ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL;
2
1CREATE TABLE orders (
2 order_id SERIAL,
3 dish_name TEXT,
4 customer_id INTEGER REFERENCES customers (id)
5);
6