- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Foreign key referencing of two DB2 tables
A foreign key is a column in a table that establishes a referential link with another table. A foreign key can be defined during creation of table (CREATE TABLE command) or it can be defined by modifying the table (ALTER TABLE command). However, before defining any key as foreign key, make sure that an index is built up on that column. We can use the below command to define an existing column CLASS in table TAB1 as a foriegn key which links to table TAB2.
ALTER TABLE TAB1 ADD FOREIGN KEY (CLASS) REFERENCES CLASSDATA (CLASS_ID);
The ALTER TABLE reserved words are followed by the name of the table which has to be modified.
Then we will use the ADD FOREIGN KEY parameter to define the name of the column which has to be defined as foreign key. Which is CLASS in this case.
At last we have to use a REFERENCES reserved word followed by the name of the database and corresponding column name which needs to be linked.
- Related Articles
- What is CASCADE rule for the foreign key on one table referencing to another table?
- Foreign Key in RDBMS
- In case of FOREIGN KEY constraint, what kind of relationship is there between MySQL parent and child tables?
- When are two tables connected with MySQL FOREIGN KEY then how can we say that the integrity of data is maintained in child table?
- Difference between Primary key and Foreign key in Database
- Difference Between Primary key and Foreign key in DBMS
- MySQL Syntax to create Foreign Key?
- Difference between Primary key and Foreign key in SQL Database
- Get a list of Foreign Key constraints in MySQL
- How to find all the foreign keys of a DB2 table TAB1?
- How to identify foreign key in MySQL DB?
- How can we assign FOREIGN KEY constraint on multiple columns?
- How to find the primary key of a DB2 table TAB1?
- How to use Primary Key Constraints and Foreign Key Constraints to enforce database integrity in Oracle?
- Verify that MySQL SET FOREIGN KEY CHECKS is set to = 1?
