Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Clustered index

Author  Topic 

WoodHouse
Posting Yak Master

211 Posts

Posted - 2010-03-10 : 07:26:51


Clustered index on nullable column is it possible?

Thanks

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-10 : 07:40:57
quote:
Originally posted by WoodHouse



Clustered index on nullable column is it possible?

Thanks




Nope.
Go to Top of Page

WoodHouse
Posting Yak Master

211 Posts

Posted - 2010-03-10 : 07:55:28
CREATE TABLE dbo.doc_exf ( column_a INT, nam varchar(10) ) ;

create clustered index idx_doc_exf1 on doc_exf(column_a)
SELECT * FROM dbo.DOC_EXF

insert into doc_exf values(null,null)
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-03-10 : 08:02:27
As WoodHouse pointed out it's perfectly possible to create a clustered index on a nullable column.

It's a primary key that you can't create.

CREATE TABLE dbo.primaryKey (
[Cola] INT NULL PRIMARY KEY

)

Results

Msg 8111, Level 16, State 1, Line 2
Cannot define PRIMARY KEY constraint on nullable column in table 'primaryKey'.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -