Groups | Blog | Home
all groups > sql server programming > march 2006 >

sql server programming : Theory on composit key


Mikael
3/22/2006 11:31:17 PM
I know that it is good practice not to use data as keys.
Would one think of a smalldatetime as data ?

My situation is that i collect historical information on financial
instruments.
I have a price table with a composit primary key of instumentId and
smalldatetime(but no time). Besides the key, I have a value for the
instrument.

I think it is ok to use the smalldatetime, but my collegue dissagrees and I
yould like a second opinion.


--
Best regards

Uri Dimant
3/23/2006 12:00:00 AM
Mikael
[quoted text, click to view]

What did you mean? Can you show us your table's structure?



[quoted text, click to view]

Uri Dimant
3/23/2006 12:00:00 AM
Mikael
http://www.sql-server-performance.com/clustered_indexes.asp
http://www.sql-server-performance.com/composite_indexes.asp





[quoted text, click to view]

David Portas
3/23/2006 12:00:00 AM
[quoted text, click to view]

That's nonsense.

[quoted text, click to view]

If a unique constraint on the datetime makes sense as a business rule then
create a key for it. That doesn't stop you adding an artificial surrogate
key if you want to - I expect that's what your colleague had in mind.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

David Portas
3/23/2006 12:00:00 AM
[quoted text, click to view]

From that page:
"A composite index is an index that is made up of more than one column. In
some cases, a composite index is also a covering index. See this URL for
information on covering indexes. Generally speaking, composite indexes (with
the exception of covering indexes) should be avoided. This is because
composite indexes tend to be wide, which means that the index will be
larger, requiring more disk I/O to read it, hurting performance."

This is plain bad advice. A non-covering composite index is very useful if a
sargable query matches the indexed columns for example. That last sentence
is no argument at all. The index is as large as the data - no more and no
less.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

Uri Dimant
3/23/2006 12:00:00 AM
Well , I think that author means that we try to avoid creating an index on
'wide' column
My understanding is if the the columns col1,col2..... have a complosite
index it is considered covered


[quoted text, click to view]

Mikael
3/23/2006 12:56:30 AM
Yes:
CREATE TABLE price
(
[InstrId] int not null,
[Stamp] smalldatetime not null,
[Price] decimal(28,10) not null,
primary key ([InstrId],[Stamp])
)


[InstrId] is a forign key to another table that contains the instruments
characteristics.

--
Best regards

Mikael


[quoted text, click to view]
AddThis Social Bookmark Button