Presentation is loading. Please wait.

Presentation is loading. Please wait.

Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record.

Similar presentations


Presentation on theme: "Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record."— Presentation transcript:

1

2 Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record. It is a unique identifier, such as a driver license number, telephone number (including area code), or vehicle identification number (VIN). A relational database must always have one and only one primary key. A primary key is a special relational database table column (or combination of columns) designated to uniquely identify all table records. A primary key's main features are: It must contain a unique value for each row of data. It cannot contain null values. 1

3 Primary key Definition A primary key is a special relational database table column (or combination of columns) designated to uniquely identify all table records. A primary key’s main features are: It must contain a unique value for each row of data. It cannot contain null values. A primary key is either an existing table column or a column that is specifically generated by the database according to a defined sequence. 2

4 Imp points Primary Key 1. A primary key cannot accept null values. 2. A primary key must be unique. 3. By default, primary key create only one clustered index in the database. 4. Each table can have one and only one primary key. 5. Each table can have one and only one clustered index. 6. Primary key can be made foreign key into another table. 7. PK support auto increments. 3

5 Example Primary Key 4

6 Foreign key Introduction Introduction : Introduction to foreign key. A foreign key is a column or combination of columns used to enforce a relationship between data in two tables. The table that contains the foreign key is called foreign key table. In the context of relational databases, a foreign key is a field (or collection of fields) in one table that uniquely identifies a row of another table or the same table. In simpler words, the foreign key is defined in a second table, but it refers to the primary key or a unique key in the first table. 5

7 Foreign Key Definition foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key of another table, thereby establishing a link between them. The majority of tables in a relational database system adhere to the foreign key concept. In complex databases and data warehouses, data in a domain must be added across multiple tables, thus maintaining a relationship between them. The concept of referential integrity is derived from foreign key theory. Foreign keys and their implementation are more complex than primary keys. 6

8 Imp points Foreign Key 1. The foreign key is a field in the table that is primary key in another table. 2. The foreign key do not create clustered or non clustered index automatically. You can create manually only. 3. The foreign key can accept multiple null values. 4. You can have more than one foreign key in a database table. 5. There are actual advantages to having a foreign key be supported with a clustered index, but you get only one per table. 7

9 Example Foreign Key 8

10 9

11 10

12 11


Download ppt "Primary key Introduction Introduction: A primary key, also called a primary keyword, is a key in a relational database that is unique for each record."

Similar presentations


Ads by Google