Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

postgres add foreign key to existing table

ALTER TABLE tblA ADD COLUMN colA VARCHAR(10); /* 1st add column */
ALTER TABLE tblA ADD CONSTRAINT colA /* Make colA on tblA a foreign key */
FOREIGN KEY (colA) REFERENCES tblB (colB); /* colB must be a pk on tblB*/
Source by www.postgresqltutorial.com #
 
PREVIOUS NEXT
Tagged: #postgres #add #foreign #key #existing #table
ADD COMMENT
Topic
Name
2+3 =