Defines a foreign key on a table or view in the current database.
sp_foreignkey tabname, pktabname, col1 [, col2] ... [, col8]
sp_foreignkey titles, publishers, pub_id
sp_foreignkey orders, parts, part, subpart
sp_foreignkey adds the key to the syskeys table. Keys make explicit a logical relationship that is implicit in your database design.
sp_foreignkey does not enforce referential integrity constraints; use the foreign key clause of the create table or alter table command to enforce a foreign key relationship.
The number and order of columns that make up the foreign key must be the same as the number and order of columns that make up the primary key. The datatypes (and lengths) of the primary and foreign keys must agree, but the null types need not agree.
The installation process runs sp_foreignkey on the appropriate columns of the system tables.
To display a report on the keys that have been defined, execute sp_helpkey.
You cannot use a Java datatype with sp_foreignkey.
See also
alter table, create table, create trigger in Reference Manual: Commands.
You must be the owner of the table or view to execute sp_foreignkey. Permission checks do not differ based on the granular permissions settings.
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|