Table-level constraints : Foreign Key « Constraints « SQL Server / T-SQL

Home
SQL Server / T-SQL
1.Aggregate Functions
2.Analytical Functions
3.Constraints
4.Cursor
5.Data Set
6.Data Type
7.Database
8.Date Timezone
9.Index
10.Insert Delete Update
11.Math Functions
12.Select Query
13.Sequence
14.Store Procedure Function
15.String Functions
16.Subquery
17.System
18.Table
19.Table Joins
20.Transact SQL
21.Transaction
22.Trigger
23.View
24.XML
SQL Server / T-SQL » Constraints » Foreign Key 
Table-level constraints


1CREATE TABLE employee (emp_no INTEGER NOT NULL CONSTRAINT prim_empl PRIMARY KEY,
2>                    emp_fname CHAR(20NOT NULL,
3>                    emp_lname CHAR(20NOT NULL,
4>                    dept_no CHAR(4NULL)
5>
6> GO
1CREATE TABLE works_on (emp_no     INTEGER NOT NULL,
2>                        project_no CHAR(4NOT NULL,
3>                        job        CHAR (15NULL,
4>                        enter_date DATETIME NULL,
5>                        CONSTRAINT prim_works PRIMARY KEY (emp_no, project_no),
6>                        CONSTRAINT foreign_works FOREIGN KEY (emp_noREFERENCES employee (emp_no))
7> GO
1> -- Specified with two declarative integrity constraints
2> -- Both constraints are table-level constraints,
3>
4> drop table works_on
5> GO
1>
2> drop table employee
3> GO
1>
           
       
Related examples in the same category
1.Define Primary key and foreign key
2.How to use foreign key constraints
3.Adding a Foreign Key to an Existing Table
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.