skip to main content
Supported SQL and Extensions : Salesforce, Marketing Cloud, Service Cloud, Dynamics, and Rollbase : Create Table for Salesforce : Foreign Key Clause

Try DataDirect Cloud Now
Foreign Key Clause


Supported only for Salesforce-based data stores. Specifies a foreign key for a constraint.


FOREIGN KEY (fcolumn_name)
REFERENCES ref_table (pcolumn_name)
Specifies the foreign key column to which the constraint is applied. The data type of this column must be the same as the data type of the column it references.
Specifies the table to which the foreign key refers.
Specifies the primary key column in the referenced table. For Salesforce, the primary key column is always the rowId column.


The following example creates the table emp with name, empId, and deptId columns in the current schema. The table contains a foreign key constraint on the deptId column, referencing the rowId in the dept table created in Column Definition. For the operation to succeed, the data type of the deptId column must be the same as that of the rowId column.
CREATE TABLE emp (name TEXT(30), empId NUMBER(9, 0) EXT_ID, deptId
TEXT(18), FOREIGN KEY(deptId) REFERENCES dept(rowId))