Global GuideLine Home HTML Tutorial JavaScript Tutorial SQL Tutorial CSS Tutorial SEO Tutorial XML Tutorial XSLT Tutorial Articles Tutorial Interview Questions and Answers Guide Jobs GuideLine Bookmark With Google Bookmark With Yahoo Bookmark With FaceBook Bookmark With Live Follow @GlobalGuideLine on Twitter Bookmark Global GuideLine
SQL Primary Key, SQL Tutorial, Global Guide Line Technology.
Bookmark this webpage. Bookmark: SQL Primary Key, SQL Tutorial Global Guideline is UNITED STATES's favorite website

      Home                    

Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.      
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.          
 SQL Alias Tables.             
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.           
 SQL Substrings.               
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.
 SQL Foreign Key.            
 SQL Cerate Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.      
 SQL Summary.                

SQL Tutorial >> SQL Primary Key.


     Back             Next     



SQL Tutorial will guide us now, that an SQL Primary Key is used to uniquely identify each row in our table. It can either be part of the actual record itself , or it can be an artificial field one that has nothing to do with the actual record. An SQL Primary Key can consist of one or more fields on a table. When multiple fields are used as an SQL primary key, they are called a composite SQL primary key.

Primary keys can be specified either when the table is created (using SQL CREATE TABLE) or by changing the existing table structure (using SQL ALTER TABLE).

Below are examples for specifying a SQL Primary Key when creating a table:

Example of SQL PRIMARY Key Constraint with MySQL Create Table.

CREATE TABLE Employees
(empID integer,
FirstName varchar(30),
LastName varchar(30),
PRIMARY KEY (empID));

Example of SQL PRIMARY Key Constraints with Oracle Create Table.

CREATE TABLE Employees
(empID integer PRIMARY KEY,
FirstName varchar(30),
LastName varchar(30));

Example of SQL PRIMARY Key Constraints wtih SQL Server Create Table.

CREATE TABLE Employees
(empID integer PRIMARY KEY,
FirstName varchar(30),
LastName varchar(30));

Below are examples for specifying an SQL Primary Key Constraint by using SQL ALTER Table Command:

SQL PRIMARY Key Constraint Example with MySQL Alter Table.

ALTER TABLE Employees ADD PRIMARY KEY (empID);

SQL PRIMARY Key Constraint Example with Oracle Alter Table.

ALTER TABLE Employees ADD PRIMARY KEY (empID);

SQL PRIMARY Key Constraint Example with SQL Server Alter Table.

ALTER TABLE Employees ADD PRIMARY KEY (empID);

Note: Before using the SQL ALTER TABLE command to add an SQL Primary Key Constraint, we'll need to make sure that the field is defined as 'NOT NULL'  in database, other wise NULL cannot be an accepted value for that field we must make that field or column as 'NOT NULL'

     Back             Next     
 
In order to link this page as Reference, click on below text area and pres (CTRL-C) to copy the code in clipboard or pres right click then copy the following lines after that past into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code:

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright © 2005-2006 www.globalguideline.com All rights reserved. Join Global Guide Line community. 160 visitors are online now