Null values

  • Hi All . I had a strange experience with composite primary key in table . In that I found if Type of the column is set to char then , it allows null values while updation; but it dosent alow it in case of inserts.I opened the data window in Enterprise manager where I discovered this . I am using sql7.0 Please comment

  • My guess,

    you have a table with nullable columns that you use with a unique index.

    A primary key constraint cannot be defined on nullable columns.

    With a unique index, you can insert/update one (1)  row with nulls in one of the columns of the unique index.

    CREATE TABLE [T_test] (

     [col1] [int]  NULL ,

     [col2] [char] (3) NULL ,

     [col3] [varchar] (50) NULL ,

     

    ) ON [PRIMARY]

    GO

    alter table [T_test]

    add CONSTRAINT [PK_T_alzdba] PRIMARY KEY  CLUSTERED

     (

      [col1],

      [col2]

    )  ON [PRIMARY]

    go

    -- errormessage :

    -- Server: Msg 8111, Level 16, State 1, Line 1

    -- Cannot define PRIMARY KEY constraint on nullable column in table 'T_test'.

    -- Server: Msg 1750, Level 16, State 1, Line 1

    -- Could not create constraint. See previous errors.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply