November 8, 2018 at 10:42 pm
Comments posted to this topic are about the item Indexing Computed Columns
November 8, 2018 at 10:53 pm
Really interesting question, thanks Steve
forgot that the results of this datetime function is non-deterministic....
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
November 9, 2018 at 1:54 am
Stewart "Arturius" Campbell - Thursday, November 8, 2018 10:53 PMReally interesting question, thanks Steveforgot that the results of this datetime function is non-deterministic....
DATEPART not always is nondeterministic.
e.g. datepart(day,'20180131') is deterministic because it returns always 31
e.g. datepart(dw,'20180131') is NONdeterministic, because it depends from localization.
November 10, 2018 at 8:00 am
I believe you meant "not" rather than "now".
However, your first example is also non-deterministic. Here's the proof.
Create table dbo.SalesOrderHeader (RN INT IDENTITY(1,1),SomeDate DATETIME);
GO
ALTER TABLE dbo.SalesOrderHeader ADD WhichDay AS datepart(day,'20180131') PERSISTED;
Msg 4936, Level 16, State 1, Line 1
Computed column 'WhichDay' in table 'SalesOrderHeader' cannot be persisted because the column is non-deterministic.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 14, 2018 at 5:57 am
nice question steve, it had me stumped
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
November 14, 2018 at 6:43 am
Jeff Moden - Saturday, November 10, 2018 8:00 AMI believe you meant "not" rather than "now".
However, your first example is also non-deterministic. Here's the proof.
Create table dbo.SalesOrderHeader (RN INT IDENTITY(1,1),SomeDate DATETIME);
GO
ALTER TABLE dbo.SalesOrderHeader ADD WhichDay AS datepart(day,'20180131') PERSISTED;Msg 4936, Level 16, State 1, Line 1
Computed column 'WhichDay' in table 'SalesOrderHeader' cannot be persisted because the column is non-deterministic.
Here an example where it is deterministic:DROP table dbo.SalesOrderHeader
Create table dbo.SalesOrderHeader (RN INT IDENTITY(1,1),SomeDate DATETIME NOT NULL);
ALTER TABLE dbo.SalesOrderHeader ADD WhichDay AS datepart(d,SomeDate) PERSISTED;
create index idx_SalesOrderHeader ON SalesOrderHeader(WhichDay)
Commands completed successfully.
The difference is the second input parameter:
with string is non-deterministic
with a valid datetime is deterministic
November 15, 2018 at 4:53 am
Carlo Romagnano - Wednesday, November 14, 2018 6:43 AMJeff Moden - Saturday, November 10, 2018 8:00 AMI believe you meant "not" rather than "now".
However, your first example is also non-deterministic. Here's the proof.
Create table dbo.SalesOrderHeader (RN INT IDENTITY(1,1),SomeDate DATETIME);
GO
ALTER TABLE dbo.SalesOrderHeader ADD WhichDay AS datepart(day,'20180131') PERSISTED;Msg 4936, Level 16, State 1, Line 1
Computed column 'WhichDay' in table 'SalesOrderHeader' cannot be persisted because the column is non-deterministic.Here an example where it is deterministic:
DROP table dbo.SalesOrderHeader
Create table dbo.SalesOrderHeader (RN INT IDENTITY(1,1),SomeDate DATETIME NOT NULL);
ALTER TABLE dbo.SalesOrderHeader ADD WhichDay AS datepart(d,SomeDate) PERSISTED;
create index idx_SalesOrderHeader ON SalesOrderHeader(WhichDay)
Commands completed successfully.The difference is the second input parameter:
with string is non-deterministic
with a valid datetime is deterministic
Wow, that just gave me a headache.LOL But hey I forgot the deterministic rule. OLD AGE is A bummer.
Thanks for the schooling!
Paul
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy