dbTalk Databases Forums  

Case-insensitive primary keys on a table

sybase.public.ase.administration sybase.public.ase.administration


Discuss Case-insensitive primary keys on a table in the sybase.public.ase.administration forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
blacklight86@gmail.com
 
Posts: n/a

Default Case-insensitive primary keys on a table - 08-02-2012 , 05:50 AM






My situation is the following: suppose you have something like:

CREATE TABLE t1(
mykey VARCHAR(255) primary key,
myvalue VARCHAR(255)
);

Since Sybase is case-sensitive over the column values, something like this would be allowed:

INSERT INTO t1(mykey, myvalue) VALUES('key', 'value');
INSERT INTO t1(mykey, myvalue) VALUES('KEY', 'VALUE');

Result:

+-----+-------+
Quote:
key | value |
+-----+-------+
KEY | VALUE |
+-----+-------+

I actually want to prevent this, and the second insertion should fail for duplicated key. Anyway, if I want to modify the value of any other column which is not primary key, for example from 'value' to 'VaLuE', I want to be able to do that, preserving the case insensitivity constraint only on the primary key.

This is possible on Oracle by creating an upper/lower case index on the table:

CREATE INDEX myindex ON t1(UPPER(mykey));

Anyway this doesn't seem to work on Sybase, since the duplicated-case insertion is still allowed.

I've found some hints around the web which would act on the DBMS configuration, through sp_configure/sp_text_configure, but I want to avoid such an intrusive solution, and apply the case sensitivity ONLY to some specific tables and ONLY on the primary keys of those tables, like I do on Oracle by creating the index through the syntax shown above.

Is this possible on Sybase?

Thanks,
-- Fabio

Reply With Quote
  #2  
Old   
Fabio Manganiello
 
Posts: n/a

Default Re: Case-insensitive primary keys on a table - 08-02-2012 , 09:21 AM






On Thursday, August 2, 2012 12:50:09 PM UTC+2, Fabio Manganiello wrote:
Quote:
My situation is the following: suppose you have something like:



CREATE TABLE t1(

mykey VARCHAR(255) primary key,

myvalue VARCHAR(255)

);



Since Sybase is case-sensitive over the column values, something like this would be allowed:



INSERT INTO t1(mykey, myvalue) VALUES('key', 'value');

INSERT INTO t1(mykey, myvalue) VALUES('KEY', 'VALUE');



Result:



+-----+-------+

| key | value |

+-----+-------+

| KEY | VALUE |

+-----+-------+



I actually want to prevent this, and the second insertion should fail forduplicated key. Anyway, if I want to modify the value of any other column which is not primary key, for example from 'value' to 'VaLuE', I want to beable to do that, preserving the case insensitivity constraint only on the primary key.



This is possible on Oracle by creating an upper/lower case index on the table:



CREATE INDEX myindex ON t1(UPPER(mykey));



Anyway this doesn't seem to work on Sybase, since the duplicated-case insertion is still allowed.



I've found some hints around the web which would act on the DBMS configuration, through sp_configure/sp_text_configure, but I want to avoid such an intrusive solution, and apply the case sensitivity ONLY to some specific tables and ONLY on the primary keys of those tables, like I do on Oracle by creating the index through the syntax shown above.



Is this possible on Sybase?



Thanks,

-- Fabio
Ok I guess this task can be considered as closed...I've found out that the only possible solution was to implement a trigger. It works, of course, even though I was looking for a less intrusive solution.

-- Fabio

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.