SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating a clustered index on Getdate function


Creating a clustered index on Getdate function

Author
Message
sandy1234
sandy1234
SSC-Enthusiastic
SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)

Group: General Forum Members
Points: 149 Visits: 253
Hi every one,
Here is my question:

I am having one table with one of the table column is having the records of get date function.
Is it possible or Is it encouraged to create a clustered index on that column containing the records of getdate() function.
Please explain.
Thank you.
GSquared
GSquared
SSC Guru
SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)

Group: General Forum Members
Points: 58287 Visits: 9730
It is definitely possible. Sometimes it's even the best column for that.

It'll depend on how you're using it. What does the column mean in the data?

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Ed B
Ed B
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1115 Visits: 1808
I do it sometimes when the primary key is a uniqueidentfier.

I don't particularly like doing it, but sometimes I can't find a better column.
sandy1234
sandy1234
SSC-Enthusiastic
SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)

Group: General Forum Members
Points: 149 Visits: 253
Thanks for the reply.
sandy1234
sandy1234
SSC-Enthusiastic
SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)

Group: General Forum Members
Points: 149 Visits: 253
i created a table
CREATE TABLE [dbo].[a_temp](
[date] [date] NULL,
[batchid] [int] NULL,
[batchid1] [int] NULL
) ON [PRIMARY]

i inserted rows into the table using get date unction as
declare @i int;
set @i=0;
while(@i<=1000)
begin
insert into a_temp(date,batchid,batchid1)
values (getdate(),@i,@i+1);
set @i =@i +1;
end


when i check the data the date column is containing the same records
as
date
2011-01-12
2011-01-12
2011-01-12
2011-01-12
2011-01-12
2011-01-12


i cannot create clustered index on the date column with this similar records in the column.
can explain?
Thank you
sandy1234
sandy1234
SSC-Enthusiastic
SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)SSC-Enthusiastic (149 reputation)

Group: General Forum Members
Points: 149 Visits: 253
i created a table
CREATE TABLE [dbo].[a_temp](
[date] [date] NULL,
[batchid] [int] NULL,
[batchid1] [int] NULL
) ON [PRIMARY]

i inserted rows into the table using get date unction as
declare @i int;
set @i=0;
while(@i<=1000)
begin
insert into a_temp(date,batchid,batchid1)
values (getdate(),@i,@i+1);
set @i =@i +1;
end


when i check the data the date column is containing the same records
as
date
2011-01-12
2011-01-12
2011-01-12
2011-01-12
2011-01-12
2011-01-12


i cannot create clustered index on the date column with this similar records in the column.
can explain?
Thank you
GSquared
GSquared
SSC Guru
SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)

Group: General Forum Members
Points: 58287 Visits: 9730
Are you just creating a clustered index, or are you creating a clustered-unique index? Or by "clustered index" do you mean "primary key"? The clustered index can have duplicate values in it, unless it's also either expressly unique, or being used as the primary key.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search