![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Consider the table: create table mytable( id int primary key autoincrement, key varchar(20) not null, lang char(2) not null, country char (2) null, value varchar(250) not null ) I want to add the following unique index: create unique index on mytable (key, lang, country) However, sybase doesn't treat NULL the same as every other database I've ever worked with. These 2 statements work, though I consider this completely flawed: insert into mytable (1, 'key', 'en', null, 'A'); insert into mytable (2, 'key', 'en', null, 'B'); The obvious workaround for this is to use a unique constraint, except that the country field can't be included (since it's null). Surely, there must be a way to make this work. Suggestions are appreciated. |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
However, sybase doesn't treat NULL the same as every other database I've ever worked with. These 2 statements work, though I consider this completely flawed: insert into mytable (1, 'key', 'en', null, 'A'); insert into mytable (2, 'key', 'en', null, 'B'); |
#5
| |||
| |||
|
|
Consider the table: create table mytable( id int primary key autoincrement, key varchar(20) not null, lang char(2) not null, country char (2) null, value varchar(250) not null ) I want to add the following unique index: create unique index on mytable (key, lang, country) However, sybase doesn't treat NULL the same as every other database I've ever worked with. These 2 statements work, though I consider this completely flawed: insert into mytable (1, 'key', 'en', null, 'A'); insert into mytable (2, 'key', 'en', null, 'B'); The obvious workaround for this is to use a unique constraint, except that the country field can't be included (since it's null). Surely, there must be a way to make this work. Suggestions are appreciated. |
#6
| |||
| |||
|
|
Not that this helps you with 9.x, but I am 90% sure that UNIQUE constraints in SQL Anywhere used to support at most one NULL value (essentially treating NULL as a special value in each domain, in exactly the same way that DISTINCT and GROUP BY treat NULLs as equal values. However, that was a long time ago, probably 12 years (and my memory isn't what it used to be). I've gone back to Watcom SQL 4.0e, and even in that version there is a restriction that UNIQUE constraints cannot be created over nullable columns. I have so far been unsuccessful in tracking down that modification, but I'm still looking. In current software, your only method to enforce at most one NULL value is with a trigger, as Nick has outlined. In discussing your situation with my staff, we are considering making a change to secondary indexes so that one can specify whether or not a single, or multiple, NULL value(s) are permitted in an index. Glenn todd wrote: Consider the table: create table mytable( id int primary key autoincrement, key varchar(20) not null, lang char(2) not null, country char (2) null, value varchar(250) not null ) I want to add the following unique index: create unique index on mytable (key, lang, country) However, sybase doesn't treat NULL the same as every other database I've ever worked with. These 2 statements work, though I consider this completely flawed: insert into mytable (1, 'key', 'en', null, 'A'); insert into mytable (2, 'key', 'en', null, 'B'); The obvious workaround for this is to use a unique constraint, except that the country field can't be included (since it's null). Surely, there must be a way to make this work. Suggestions are appreciated. -- Glenn Paulley Director, Engineering (Query Processing) iAnywhere Solutions Engineering EBF's and Patches: http://downloads.sybase.com choose SQL Anywhere Studio >> change 'time frame' to all To Submit Bug Reports: http://case-express.sybase.com SQL Anywhere Studio Supported Platforms and Support Status http://my.sybase.com/detail?id=1002288 Whitepapers, TechDocs, and bug fixes are all available through the iAnywhere Developer Community at www.ianywhere.com/developer |
![]() |
| Thread Tools | |
| Display Modes | |
| |