Question:
oracle sql composite key?
anonymous
2007-04-23 03:59:16 UTC
I have a major projecty to do which includes using,primary keys,foreign keys and composite keys. The first two i know what they are and how to use them but i havent got a clue about composite keys. Does anyone know what they are and how they are used?
Three answers:
arindamgdastidar
2007-04-23 05:05:18 UTC
primary key - A column in a table that uniquely identifies a row in a table

foreign key - A column in a table that does not uniquely identify rows in that table, but is used as a link to matching columns in other tables.

composite key - A primary key that consists of more than one column



For example consider the following simplified table structure:

Table 1: Employee

Columns: Employee_ID (primary key), Employee_Name

Each Employee_ID will mean one unique employee



Table 2: Employee_Salary

Columns: Employee_ID, Salary, Salary_Date

This table will have the salaries for all employees for all different months. So there will be multiple occurances of the same Employee_ID in the table.

Here Employee_ID is the foreign key



Now in the second table, we can declare the combination of the Employee_ID and the Salary_Date as a Composite Primary key. Because no employee will receive salary more than once in a month, the so Salary_Date and Employee_ID combination will always be unique.
fechter
2016-12-16 18:14:21 UTC
does no longer CustID link the two tables at the same time? the reality that it wasn't defined as a foreign places places key constraint does no longer replace the reality that they are appropriate. Constraints in user-friendly terms enforce database integrity, they do no longer define what you're able to desire to and would desire to't do in an sq. actuality. i think of of you like some subject alongside those lines: replace shopper SET CustActiveStatus = 'somevalue' the placement CustID IN (   % CustID   from BILLING   the placement ); ETA: confident, replace the " with a '. yet this is likewise incorrect: the placement sysdate-30 BillDueDate you desire some subject between sysdate-30 and BillDueDate. > is probably what you like.
mindreader
2007-04-23 04:20:56 UTC
A composite key is exactly the same as a single column primary key, except that it consists of more than one column.



for ex.

CREATE TABLE track(

album CHAR(10) NOT NULL,

dsk INTEGER NOT NULL,

posn INTEGER NOT NULL,

song VARCHAR(255),

PRIMARY KEY (album, dsk, posn)

)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...