what is primary key?

Answer Posted / vinod singh kushwah

A primary key is used to uniquely identify each row in a
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). A primary key can consist of
one or more fields on a table. When multiple fields are
used as a primary key, they are called a composite key.
Primary keys can be specified either when the table is
created (using CREATE TABLE) or by changing the existing
table structure (using ALTER TABLE).
Below are examples for specifying a primary key when
creating a table:

MySQL:

CREATE TABLE Customer
(SID integer,
Last_Name varchar(30),
First_Name varchar(30),
PRIMARY KEY (SID));

Oracle:

CREATE TABLE Customer
(SID integer PRIMARY KEY,
Last_Name varchar(30),
First_Name varchar(30));

SQL Server:

CREATE TABLE Customer
(SID integer PRIMARY KEY,
Last_Name varchar(30),
First_Name varchar(30));
Below are examples for specifying a primary key by altering
a table:

MySQL:

ALTER TABLE Customer ADD PRIMARY KEY (SID);

Oracle:

ALTER TABLE Customer ADD PRIMARY KEY (SID);

SQL Server:

ALTER TABLE Customer ADD PRIMARY KEY (SID);

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if you lost a data file?

574


What is oracle analytical function?

522


What is the Tune Query

1837


What are transaction isolation levels supported by oracle?

572


what is insert all statement in sql

5491






How to define an explicit cursor in oracle?

595


How to run the anonymous block again?

591


What privilege is needed for a user to create indexes in oracle?

567


IS it possible to built the oracle database without setting the kernal parameters?

1759


How do we represent comments in oracle?

621


Why oracle is used?

575


Typically, where is the conventional directory structure chosen for Oracle binaries to reside?

1576


How to write a query with an inner join in oracle?

560


What are the differences between date and timestamp in oracle?

549


Explain the use of indexes option in exp command.

590