Composite Primary Key ?

Posted by Sandeepkasar under Sql Server on 1/26/2012 | Points: 10 | Views : 1295 | Status : [Member] | Replies : 2
Hi,
I am bit confused over composite Primary key

For example
I have 2-table as fallows

1. 2.
SaleOrder SaleDetails

RecordNo, RecordNo,
RecordDate, RecordDate,
SalesType, SalesType,
CustomerId, SerialNo,
SaleAmount, ItemId,
FinancialYear, ItemAmount,
CompanyId, FinancialYear,
CompanyId,


My current composite primary key is applied on table SalesOrder
And on (RecordNo,SalesType,FinancialYear, CompanyId) which are
also present in 2nd table SalesDetails .

So every time when I required a particular record I have to apply join
SalesOrder and SalesDetails on each columns of composite primary key.

Is it a good idea to denormalized all these columns ? and addind new column Suppose.. (PKeyOrder = RecordNo+SalesType+FinancialYear+CompanyId),
And create a single primary key on newly added PKeyOrder column.

This will surely reduce no of joints but increases overheads on by tables,
Which is better solution.


Thanks,

Sandeep




Responses

Posted by: Naraayanan on: 2/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Apply Join query for your requirement.

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Sandeepkasar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/21/2012 [Member] Starter | Points: 25

Up
0
Down
CREATE TABLE USEDETAILS(USERID INT,USERLIST_ID INT PRIMARY KEY(USERID,USERLIST_ID))



HOPE THIS WILL HELP

REGARDS


sriram

Sandeepkasar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response