English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

Ok, there are technical ways to define this, but I am going to put it into English you will understand (I dont know how techy you are).

A primary key is something (usually one or more columns) that uniquely identifies the row of data in your tables in your database.

For example if you have a "Customer" table, you might have a Customer id column. If no two customers have the same customer id, that would be a great primary key.

For example if you have an "Employee" table, social security number might be the unique key - or Employee Number.

There are some entities that need many columns to make up their unique key.

For example, if you have an "Address" table, the only way you can be sure that the address is unique is by having a primary key that consists of many columns - perhaps the Street Number, Street Name and Zip code

Before you can work out what the primary keys are in a database, you have to be sure that you have designed your tables well. If you have designed your tables well, each row in each table will contain one obviously identifiable entity. However, some people for ease of set up (they think) have tables that contain lots of different entities all in one. That is when it is difficult to choose a primary key.

For example, if you have a table called "Employees" that contains not just the employee id and name but also their address, this may cause problems you didnt anticipate. Some employees (maybe rarely, but still) will have two addresses - one that they live in when in town, one that they live in when out of town.. so the Employees table might have two rows with the same Employee Id. In this case, the Employee Id cant be the primary key unless the table is split into an Employee table and an Address table for example. Otherwise, your unique key would have to be EmployeeId PLUS Street Number PLUS Street Name PLUS zip code.

Hope this makes some sense..

Now for the techy bit (ignore if you wish)

A Primary key is a nonrepeating, unique key consisting of one or many columns that identifies within a table the row, the whole row and nothing but the row.

In a well-normalized table, there will be no repeating groups, nothing will be dependent upon anything but the key, and nothing will be dependent upon part of the key.

2006-08-04 14:48:13 · answer #1 · answered by Michelle S 2 · 0 0

I don't know what database you are using, but using MySQL the command "describe (tablename);" will show you the primary key for that table.

2006-08-04 14:44:09 · answer #2 · answered by Bryan A 5 · 0 0

fedest.com, questions and answers