QTP Forum
Shopmotion


composite primary key Empty
Search
 
 

Display results as :
 


Rechercher Advanced Search

Poll
Keywords

Latest topics
September 2019
MonTueWedThuFriSatSun
      1
2345678
9101112131415
16171819202122
23242526272829
30      

Calendar Calendar

Affiliates
free forum


composite primary key

Go down

composite primary key Empty Re: composite primary key

Post by thomasdfg on Thu Jun 19, 2014 11:31 am

A composite key has more than one attribute (field). In this example we store details of tracks on albums - we need to use three columns to get a unique key - each album may have more than one disk - each disk will have tracks numbered 1, 2, 3...
The primary key must be different for each row of the table. The primary key may not contain a null.
thomasdfg
thomasdfg

Posts : 11
Join date : 2014-06-18
Age : 34
Location : Hyderabad

View user profile

Back to top Go down

composite primary key Empty Re: composite primary key

Post by Gajre on Sun Nov 25, 2012 4:20 pm

When you use the multiple-column
constraint format, you can create a composite key. A composite
key
specifies multiple columns for a primary-key or foreign-key
constraint.

The below example creates two tables. The first table has
a composite key that acts as a primary key, and the second table has
a composite key that acts as a foreign key.

CREATE TABLE accounts (
acc_num INTEGER,
acc_type INTEGER,
acc_descr CHAR(20),
PRIMARY KEY (acc_num, acc_type));

CREATE TABLE sub_accounts (
sub_acc INTEGER PRIMARY KEY,
ref_num INTEGER NOT NULL,
ref_type INTEGER NOT NULL,
sub_descr CHAR(20),
FOREIGN KEY (ref_num, ref_type) REFERENCES accounts
(acc_num, acc_type));


In this example, the foreign key of the sub_accounts table, ref_num and ref_type,
references the composite key, acc_num and acc_type,
in the accounts table. If, during an insert or update, you
tried to insert a row into the sub_accounts table whose value
for ref_num and ref_type did not exactly correspond
to the values for acc_num and acc_type in an existing
row in the accounts table, the database server would return
an error.

A referential constraint must have a one-to-one relationship
between referencing and referenced columns. In other words, if the
primary key is a set of columns (a composite key), then the foreign
key also must be a set of columns that corresponds to the composite
key.

Because of the default behavior of the database server,
when you create the foreign-key reference, you do not need to reference
the composite-key columns (acc_num and acc_type) explicitly.
You can rewrite the references section of the previous example as
follows:

FOREIGN KEY (ref_num, ref_type) REFERENCES accounts
Gajre
Gajre
Admin

Posts : 37
Join date : 2012-06-17
Age : 36
Location : Hyderabad

View user profile https://qtpelearning.forumotion.com

Back to top Go down

composite primary key Empty composite primary key

Post by sriharish2 on Fri Nov 23, 2012 9:18 pm

What is composite primary key?
Question

sriharish2

Posts : 8
Join date : 2012-10-31

View user profile

Back to top Go down

composite primary key Empty Re: composite primary key

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum