Question

I'm studying for an exam in database and in one of my exercises I should state whether an INSERT [...] is possible for this database:

CREATE TABLE A (
   a1 INTEGER NOT NULL PRIMARY KEY,
   a2 CHAR(10) NOT NULL,
   a3 CHAR(10) NOT NULL,
   CHECK(a2<a3)
)

What does that last bit mean (a2<a3)? It's a string, so what does it compare, the length or what? Some help would be awesome, thanks.

Was it helpful?

Solution

insert into A values (0, 'a', 'b'); is possible

insert into A values (1, 'b', 'a'); throws an exception

CHECK(a2 < a3) only allows inserts where the value of a2 comes first in the alphabet (is lower), compared to a3.

You can try to execute select ascii('a'); so you can see the ASCII-code of the character (here: 97).

Edit: Be aware that capital letters like A has different ascii codes than small modes like a

Link to an ASCII-code table

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top