Sets work in a similar way to enumerated fields : ENUM « Data Type « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Data Type » ENUM 




Sets work in a similar way to enumerated fields
   
mysql>
mysql> CREATE TABLE test7 (fruit SET('apple','mango','litchi','banana'));
Query OK, rows affected (0.00 sec)

mysql>
mysql> INSERT INTO test7 VALUES('banana');
Query OK, row affected (0.00 sec)

mysql>
mysql> INSERT INTO test7 VALUES('litchi');
Query OK, row affected (0.00 sec)

mysql>
mysql> INSERT INTO test7 VALUES('paw-paw');
Query OK, row affected, warning (0.00 sec)

mysql>
The difference of a SET type is that you can add multiple instances:
mysql>
mysql> INSERT INTO test7 VALUES('apple,mango');
Query OK, row affected (0.00 sec)

mysql>
mysql> SELECT FROM test7;
+-------------+
| fruit       |
+-------------+
| banana      |
| litchi      |
|             |
| apple,mango |
+-------------+
rows in set (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO test7 VALUES('mango,apple');
Query OK, row affected (0.00 sec)

mysql>
mysql> SELECT FROM test7 ORDER BY fruit;
+-------------+
| fruit       |
+-------------+
|             |
| apple,mango |
| apple,mango |
| litchi      |
| banana      |
+-------------+
rows in set (0.00 sec)

mysql>
mysql> drop table test7;
Query OK, rows affected (0.00 sec)

   
    
    
  














Related examples in the same category
1.How to use enum
2.Use two ENUM data type in a table
3. Storage Comparisons of ENUM and SET
4.Insert String value as ENUM
5.Define and use ENUM data type
6.Define 'Male' and 'Female' as Enum
7.ENUM: Enumeration of up to 65,535 strings
8.With ENUM you can manage a list of up to 65,535 character strings.
9.Sorting ENUM Values
10.MySQL uses the internal numeric values for sorting for enum value
11.Sort ENUM values in lexical order
12.Consider changing the column type to ENUM, if you always sort a non-enumeration column in a specific non-lexic
13.Use ALTER TABLE to convert the name column to an ENUM that lists the colors in the desired sort order:
14.Add to mytbl an ENUM column e that has several members
15.Enumerating a Many-to-Many Relationship
16.Configure an ENUM column and a SET column
17.If you add an invalid value to ENUM columns, an empty string ("") is inserted instead
18.Perform queries on enumerated fields based on their indexes
19.The ENUM and SET Column Types
20.Enumeration values aren't limited to being single letters or uppercase.
21.An ENUM column definition may list up to 65,535 members.
22.Insert value to enum type column
23.The SET datatype, like ENUM, is declared using a comma-separated list of quoted strings that define its valid
24.enum value index
25.Enum for month names
26.Enum type column
27.Order by enum value
28.Using foreign key as an enum type
29.Use operators to specify a range of values.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.