|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 9:46 AM
Points: 15,
Visits: 226
|
|
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.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
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
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Yesterday @ 2:58 PM
Points: 494,
Visits: 1,514
|
|
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.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 9:46 AM
Points: 15,
Visits: 226
|
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 9:46 AM
Points: 15,
Visits: 226
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 9:46 AM
Points: 15,
Visits: 226
|
|
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
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
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
|
|
|
|