Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , ,

Sponsored Links



what does primary key mean in SQL?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-02-2010
Member
 
Join Date: Dec 2009
Posts: 32
what does primary key mean in SQL?

Hello friend,

I just started to learn SQL. I have knowledge of java and C++, but SQL is entirely different from these language. I know how to create simple table in SQL. But I am quit confused about 'primary key'. I don't know what is 'primary key'. I want to know what is the need of using primary key. Do you have sound knowledge about 'primary key'? if yes then please let me know the same. I am waiting for your reply.
Reply With Quote
  #2  
Old 10-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
Re: what does primary key mean in SQL?

Hi friend,

The primary key helps to uniquely identify each row in a table. It can be a part of a permanent record, or be an artificial field (a field that has nothing to do with the actual recording). The primary key can represent one or more fields in a table. When the primary key represents several fields, it is called composite key. It is possible to to specify the primary key while creating the table (using CREATE TABLE) Or changing the structure of the existing table (through ALTER TABLE).
Reply With Quote
  #3  
Old 10-02-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
Re: what does primary key mean in SQL?

In a relational database, a primary key is a unique constraint that can uniquely identify a record in a table. A primary key can consist of one or more fields of the table. Two separate lines of the table can have different values for the fields defined in the primary key. It is possible to define for a table several unique constraints, but at most one primary key. it is possible to have a primary key field1 (PK) of a table to point to the primary key field1 (pk) a table B.
Reply With Quote
  #4  
Old 10-02-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: what does primary key mean in SQL?

The primary key of a table should be placed on fields that identify each table row. It may therefore seem helpful to place a primary key on a social security number for example, but we prefer to use a completely independent primary key business data to ensure that the field is always filled (a stranger or a child may have no social security number) and does not change in time. All databases provide mechanisms that support numbering used for primary keys.
Reply With Quote
  #5  
Old 10-02-2010
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,832
Re: what does primary key mean in SQL?

It is not necessary to define an index on columns defining the primary key because an index is implicitly associated with the primary key. The set consists of a primary key and a foreign key used to establish Relations between tables. You can put a constraint preventing contain duplicates in a field but without necessarily being a primary key field. This constraint is implicit in a field primary key.
Reply With Quote
  #6  
Old 10-02-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
Re: what does primary key mean in SQL?

The primary key can be defined in the following ways:

Quote:
ALTER TABLE nameOfTable ADD [ CONSTRAINT constraint identifier ]
PRIMARY KEY ( expression {, expression}... )
Quote:
CREATE TABLE nameOfTable( col INT PRIMARY KEY, col2 CHAR(20),
...
)
For more details visit below link:
http://msdn.microsoft.com/en-us/library/ms191236.aspx
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "what does primary key mean in SQL?"
Thread Thread Starter Forum Replies Last Post
How many partitions will you do in your Primary HDD Quintessa Polls & Voting 6 2 Weeks Ago 07:22 PM
VDI Primary on VirtualBox Who is it Software Development 5 16-07-2010 04:49 AM
Set up Old harddrive as primary TAKODA Hardware Peripherals 3 07-07-2009 10:08 AM
Cannot create new primary partition - only 2 primary partitions on disk Vistanoob Windows Vista Performance 5 28-05-2009 10:43 PM
Vista Ultimate changed Primary partitions to Dynamic and created hidden partition with the primary "partitions" listed as Volumes craigv Operating Systems 2 03-06-2008 04:16 PM


All times are GMT +5.5. The time now is 11:31 AM.