Maybe I am missing something very obvious, but I couldn't do it:
begin tran
go
create table foo (
f1 int not null,
f2 int not null,
f3 as (f1 + f2) not null primary key clustered)
go
rollback tran
go
This returns:
Server: Msg 8183, Level 16, State 1, Line 8
Only UNIQUE or PRIMARY KEY constraints are allowed on computed columns.Never mind, this worked:
begin tran
go
create table foo (
f1 int not null,
f2 int not null,
f3 as isnull((f1 + f2), 0) primary key clustered)
go
rollback tran
go|||My machines don't care for that either, although logically they shouldn't object.
-PatP|||OK...for the life of me....why?|||Actually it sarted with RogerWilco's post (http://www.dbforums.com/t1006214.html (http://www.dbforums.com/t1006214.html)), where I was trying to demonstrate that while having 4 fields instead of 1 does not mean that you will have to perform every join on all 4 fields. And sure enough, you also can make the computed column a PK, and have a UNIQUE constraint defined on it, needless to say create indexes. Of course, when we start talking about doing those things, Brett's belief that "one should leave all connection settings to default" would have to be shattered, because this is exactly the situation where not only you have to change them, but also understand the implications of changing each and one of them...But that may be easily transfered to a dedicated thread...I already see its name...
No comments:
Post a Comment