Self-Referencing Tables : REFERENCES « Constraints « SQL Server / T-SQL Tutorial






4> CREATE TABLE employee
5> (
6> emp_id      int            NOT NULL PRIMARY KEY,
7> emp_name    varchar(30)    NOT NULL,
8> mgr_id      int            NOT NULL REFERENCES employee(emp_id)
9> )
10> GO
1>
2> INSERT employee VALUES (1, 'Chris Smith', 1)
3> GO

(1 rows affected)
1>
2>
3> drop table employee;
4> GO








7.4.REFERENCES
7.4.1.Self-Referencing Tables
7.4.2.Primary key and foreign key
7.4.3.Making a Table be Self-Referencing
7.4.4.ON UPDATE CASCADE ON DELETE NO ACTION
7.4.5.REFERENCES customer(cust_id) (from another table)