Reputation: 155
Can I use one defined Primary key in more than one table.For example I have an Item Table that has Item_ID, but I also want to write this ID in Vehicle and Piece table as Primary Key.Can this be possible?Because, I want to form a base table and then sub tables.Vehicle has its own attributes.
Upvotes: 0
Views: 915
Reputation: 10063
1. First of all, purpose of Primary key is to uniquely identify a row
of a table.
2. Is it possible that data of a 'column' can uniquely identify a row
of 3 tables?
3. Practically not! Then that means it's not in normalized form(not
atomic)
4. One primary key of a table can not be referenced as primary key of
another table and it can be of foreign key. That is how it's
designed.
Practicle Example:
The primary key of a relational table uniquely identifies each record in the table. It can either be a normal attribute that is guaranteed to be unique (such as Social Security Number in a table with no more than one record per person) or it can be generated by the DBMS (such as a globally unique identifier, or GUID, in Microsoft SQL Server). Primary keys may consist of a single attribute or multiple attributes in combination. Imagine we have a student records database that contains three tables. The first table, STUDENTS, contains a record for each student at the university. The second table, CLASSES, contains a record for each class session offered. The third table, ENROLLMENT, contains student enrollment records (e.g. each record represents a single student enrolling in a single course). There would be multiple records for each student (representing all the classes that student is enrolled in) and multiple records for each class session (representing all the students enrolled in that class). A student's unique student ID number would be a good choice for a primary key in the STUDENTS table.
Hope this helps
Upvotes: 1