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

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
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
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
w__w___w___.___j__ava__2s__.__c___o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.