January 12, 2011 at 11:14 am
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.
January 12, 2011 at 11:20 am
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
January 12, 2011 at 11:25 am
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.
January 12, 2011 at 3:12 pm
Thanks for the reply.
January 12, 2011 at 3:42 pm
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
January 12, 2011 at 3:43 pm
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
January 13, 2011 at 6:43 am
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
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply