indexing - SQL Server : For 3 columns, difference between "one index per column" / "one index for all" -


i configuring simple table in sql server. named "log" , might expect, used record logs, later monitoring/searching/grouping use of various applications in various manners.

the table declared (simple syntax) :

log {    user   varchar(8),    timestamp  datetime,    appname   varchar(16) } primary key(user,timestamp,appname) 

should index each column in separate index? 3 in same index? clustered / non-clustered?

i'd happy see logic/knowledge apply here.

i'd suggest making timestamp clustered index... since clustered index particularly efficient on columns searched ranges of values, , seems describe how querying data.

additionally, i'm assuming timestamp sequential, make inserting new data clustered index less expensive if there random distribution of data being inserted.

it doesn't sound searching user or appname, wouldn't recommend adding indexes columns unless plan on joining on these values or using them in where clause somewhere down road.

you suggested adding 3 fields index, when this, index used if "leading edge" included in search...

for example, if index (user, timestamp, appname), you're searching timestamp , appname, index not used. because of this, important consider how data queried when creating indexes.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -