Sunday, April 17, 2011

Can a set in MySQL be 0?

Can a set in MySQL be 0?

From stackoverflow
  • Sure, why not?

    CREATE TABLE t_set (id INT NOT NULL PRIMARY KEY, value SET('one', 'two'));
    
    INSERT
    INTO    t_set
    VALUES  (1, 1);
    
    SELECT  *
    FROM    t_set;
    
    
    id    value
    ----  ------
       1  one
    
    UPDATE  t_set
    SET     value = 0;
    
    SELECT  *
    FROM    t_set;
    
    id    value
    ----  ------
       1
    
  • A SET is a string object that can have zero or more values, each of which must be chosen from a list of allowed values specified when the table is created. SET column values that consist of multiple set members are specified with members separated by commas (“,”). A consequence of this is that SET member values should not themselves contain commas.

    For example, a column specified as SET('one', 'two') NOT NULL can have any of these values:

    '' 'one' 'two' 'one,two'

    http://dev.mysql.com/doc/refman/5.1/en/set.html

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.