473,806 Members | 2,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Indexes and UniqueIdentifie r Fields

I have a table that contains articles (as in, newspaper articles, blog
articles, whatever). I need to use a column of type uniqueidentifie r
because one of the requirements is that I be able to write the articles
out to XML or import them from XML, and references (as in, "for more
info read this: 2323-232-90934" have to still work after the export and
import).

So as a minimum, the table is going to look like this:

CREATE TABLE Articles (
ArticleID uniqueidentifie r,
PublishDate datetime,
Title nvarchar (50)
ArticleContent ntext
)
GO

ALTER TABLE Articles ADD
CONSTRAINT PK_Articles
PRIMARY KEY NONCLUSTERED (ArticleID)
WITH FILLFACTOR = 100
GO

As you can see, I'm not going to use a clustered index on a column of
type UniqueIdentifie r. I got that much from this newsgroup and from
websites on sql server performance tuning.

Two questions. 1: I will obviously need to list recent articles. I'll
need to do: select top 10 ArticleID, PublishDate, Title from Articles
order by PublishDate desc

Will there be any problem with an index on a datetime field to make
that query faster?

CREATE UNIQUE CLUSTERED INDEX IX_Articles_Pub lishDate
ON Articles (PublishDate DESC)
WITH FILLFACTOR = 100
GO

Question 2: Is there anything else that I can do here that I'm missing?
Should I maybe also have a auto-increment field and put the clustered
index on it instead?

Thanks in advance
chris

Aug 26 '05 #1
4 2466
ch************* ***@gmail.com (ch************ ****@gmail.com) writes:
So as a minimum, the table is going to look like this:

CREATE TABLE Articles (
ArticleID uniqueidentifie r,
PublishDate datetime,
Title nvarchar (50)
ArticleContent ntext
)
GO

ALTER TABLE Articles ADD
CONSTRAINT PK_Articles
PRIMARY KEY NONCLUSTERED (ArticleID)
WITH FILLFACTOR = 100
GO

As you can see, I'm not going to use a clustered index on a column of
type UniqueIdentifie r. I got that much from this newsgroup and from
websites on sql server performance tuning.
Certainly clustered index on Uniqueidentifie r and a fillfactor of 100
is a recipe for disaster. However, SQL Server MVP Greg Linwood pointed
out to me that with a low fill factor, uniqueidentifie r very can be a
good choice for a clustered index. New rows will be inserted in existing
gaps. But this requires that you reindex when the gaps are starting
to run out.
Two questions. 1: I will obviously need to list recent articles. I'll
need to do: select top 10 ArticleID, PublishDate, Title from Articles
order by PublishDate desc

Will there be any problem with an index on a datetime field to make
that query faster?

CREATE UNIQUE CLUSTERED INDEX IX_Articles_Pub lishDate
ON Articles (PublishDate DESC)
WITH FILLFACTOR = 100
GO


PublishDate could indeed be a good choice for the clustered index,
but I don't think you should make it unique. Surely, you must be able
to store two articles published the same day! (I'm assuming that you
will keep the time portion to midnight.)


--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 26 '05 #2
Thanks for the advice. I've decided to add a column of type int
(indentity) and make that the clustered index. The result will be the
same as what I was looking for in indexing publishdate, but it's on an
simple integer field.

chris

Aug 28 '05 #3
ch************* ***@gmail.com (ch************ ****@gmail.com) writes:
Thanks for the advice. I've decided to add a column of type int
(indentity) and make that the clustered index. The result will be the
same as what I was looking for in indexing publishdate, but it's on an
simple integer field.


Say that you have a query:

SELECT * FROM tbl WHERE publishdate BETWEEN '20050601' AND '20050630'

If you have a clustered index on publishdate, SQL Server will do a
clustered index seek in this interval and find the rows quickly. If you
cluster on the identity column instead, SQL Server will have to scan
the entire table. If you add a non-clustered index on publishdate, SQL
Server may use that index, but if the interval is too wide, it will estimate
that nc-index + bookmark lookup is too expensive, and scan the table
nevertheless.

This is because, there is no way that SQL Server can assert that the
date follows the identity column.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Aug 28 '05 #4
Have you thought about getting a textbase (document management tool) to
do this? SQL is not the answer to everything.

Aug 28 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4493
by: Bernie | last post by:
Greetings, I have 3 servers all running SQL Server 2000 - 8.00.818. Lets call them parent, child1, and child 2. On parent, I create a view called item as follows: CREATE view Item as select * from child1.dbchild1.dbo.Item union all select * from child2.DBChild2.dbo.Item
1
2021
by: Vinny | last post by:
Can anyone help me with this strange problem please? I have a stored procedure, with a parameter defined as a uniqueidentifier. The procedure does a select with a number of joins, and filters within the Where clause using this parameter. (@orderHeader_id uniqueidentifier) SELECT *
4
1786
by: WindAndWaves | last post by:
Hi Everyone Is there anyone who has some sound rules of thumb for using indexes. I see that, for example, access automatically adds them to linked tables, but I feel, they are probably of more use in text fields (for sorting purposes), etc.... Keen to hear your ideas.
5
1855
by: Bruce Rusk | last post by:
I have a question about indexing multiple fields and whether it's redundant to index the individual fields separately. As I understand it, if there is an index on two fields, say idxFullName which includes LastName and FirstName, in that order, it would be redundant to create a separate index on LastName since idxFullName would already be indexing LastName. But it would be necessary to create a separate index for FirstName to assist with...
14
19684
by: Jeff | last post by:
This is the first time that I remember ever having too many indexes on a table, but it has happened. I have en employees table and store in many places, on tables, the id of the employee that performed some action. Yes, I know, that could be in an audit trail but it isn't. For example, who printed a sales order, who processed it etc is stored on the sales orders table. Well, I have run out of indexes on the employees table when trying...
3
1613
by: Rafael tejera | last post by:
I have a table with many uniqueidentifiers fields, sometimes some fields are empty, but I cannot sent an empty string to a uniqueidentifier, How I can sent null values whenever is necesary without having to rewrite my sql statement. I have sent values like "" and "null" and it does not work. what I can do? Rafael
0
7603
MMcCarthy
by: MMcCarthy | last post by:
The more data you include in your tables the more you will need to have indexes to search and sort that data. However, there is a balance between having enough indexes and too many. Too many indexes will slow down the speed of updates on your records. Access presets a number of Indexes for you. If you look in Tools ... Options under the Tables/Queries tab you will see that under "Auto Index on Import/Create" there is a list as follows: ...
5
6694
by: DotNetNewbie | last post by:
Hi, I am developing an application that has to scale and be very efficient, and I am using asp.net membership in my application. I set things up in my Users table (it has extra columns that I need over and above what aspnet_users has): UserID INT Membershipuserid uniqueidentifier
0
2570
by: Jeddah | last post by:
Dear Sirs, My name is Joseph. I have a problem within my stored procedure that selects Userid and Password if the user's input fields are correct. I used Asp.net configuration functionality to build membership table in my database. However, in my membership table, UserId and Password datatypes are defined as uniqueidentifier and nVarchar, which were generated automatically when I used the Asp.net configuration functionality. Now, in my...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10624
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.