08 SQL3 DataTypes
08 SQL3 DataTypes
1 2
3 4
5 6
Enumerated Types SET Types
• You can create enumerated types • The SET type can have zero or more values from a list of permitted
values
• CREATE TABLE sizes ( name ENUM('small', 'medium', 'large'))
• Each value should appear at most once
• Enumerated types have an index that starts at 1
• CREATE TABLE mytable (col SET('a', 'b', 'c', 'd'));
• Index zero is error (a value that was not defined, e.g. ‘huge’)
• Insert values like this
• Enumerated values are sorted by their index – which is the order in
which they were defined so small < medium < large • INSERT INTO myset (col) VALUES ('a,d') ;
7 8
9 10
11 12
Data Type Integrity
• You can specify things about the qualities of data that is to be stored
• We have seen that decimal allows you to be precise about decimal
places
• You can specify whether or not a field can contain NULL
• Enumerating types or using sets helps you control what values go into
a field
• Dates are automatically checked for correct format
• Variable length fields have a maximum size that cannot be exceeded
13