Many to many using a primary-key and foreign-key relationship : FOREIGN KEY « Table « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Table » FOREIGN KEY 
6. 16. 10. Many to many using a primary-key and foreign-key relationship
SQL> CREATE TABLE Course
  2     (course_id        VARCHAR2(10NOT NULL,
  3      course_name      VARCHAR2(20),
  4      PRIMARY KEY (course_id));

Table created.

SQL>
SQL> CREATE TABLE emp
  2     (stud_id    VARCHAR2(10NOT NULL,
  3      stud_name  VARCHAR2(20),
  4      PRIMARY KEY (stud_id));

Table created.

SQL>
SQL> CREATE TABLE Enrolls_in
  2     (course_id  VARCHAR2(10NOT NULL,
  3      stud_id    VARCHAR2(10NOT NULL,
  4      PRIMARY KEY (course_id, stud_id),
  5      FOREIGN KEY (course_idREFERENCES Course (course_id)
  6      ON DELETE CASCADE,
  7      FOREIGN KEY (stud_idREFERENCES emp (stud_id)
  8      ON DELETE CASCADE);

Table created.

SQL>
SQL> drop table Course cascade constraints;

Table dropped.

SQL> drop table emp cascade constraints;

Table dropped.

SQL> drop table Enrolls_in;

Table dropped.

SQL>
6. 16. FOREIGN KEY
6. 16. 1. Adding a FOREIGN KEY Constraint
6. 16. 2. ON DELETE CASCADE clause with a FOREIGN KEY constraint
6. 16. 3. Use the ON DELETE SET NULL clause with a FOREIGN KEY constraint
6. 16. 4. ORA-02298: cannot validate (JAVA2S.PRODUCT_ORDER_FK_PRODUCT) - parent keys not found
6. 16. 5. A foreign key to reference itself
6. 16. 6. ORA-02270: no matching unique or primary key for this column-list
6. 16. 7. Add constraint foreign key references
6. 16. 8. Violate a foreign key
6. 16. 9. Disable foreign key
6. 16. 10. Many to many using a primary-key and foreign-key relationship
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.