Re: Composite Key in Sql Server 2008

Author: Ajoy Khaund

Posted: 2011-09-21 at 11:20:10

Thanks.

I have a transactions table where before doing an entry I check if that

record exists by empno + date + shiftno. If the seek fails I add the records

else I overwrite existing records. Maybe in SQL server we have to do it

slightly differently.

--------------------------------------------------

From: "Stephen Russell" <srussell705@gmail.com>

Sent: Wednesday, September 21, 2011 6:24 PM

To: <profoxtech@leafe.com>

Subject: Re: Composite Key in Sql Server 2008

> On Wed, Sep 21, 2011 at 7:37 AM, Ajoy Khaund <akhaund@gmail.com> wrote:

>> Hi,

>>

>> I have a composite key in VFP like

>>

>> Padl(empno,4,'0') + DTOS(kdate) + Str(shiftno,1)

>>

>> I use this index to do a seek to find out if a record exists for a

>> particular employee on a particular date in a particular shift.

>>

>> How can I do that in sql. I am going to use cursor adaptors.

>>

> -------------

>

> Do you know how to create indexs in SQL Server tables that span

> multiple columns?

>

> CREATE UNIQUE NONCLUSTERED INDEX newKey ON YourTable

> (

> empNumber,

> kDate,

> shiftNo

> ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,

> ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

> GO

>

>

> In your where clause :

> Where empNumber = YourmakeshiftValue

> and kDatebetween StartOfDay and EndOfDay

> and shftno = 1

>

> As a heads up. This index may never get used if the table is joined

> so all of this is mute.

>

>

> --

> Stephen Russell

>

> Unified Health Services

> 60 Germantown Court

> Suite 220

> Cordova, TN 38018

>

> Telephone: 888.510.2667

>

> 901.246-0159 cell

>

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/profox

OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/7572B5A7801D405DA3B483F240409EC9@ajoykcompaq

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2011 Ajoy Khaund