Define and use varchar : Varchar « Data Type « SQL / MySQL






Define and use varchar

  
/*
mysql> Drop table Product;

mysql> CREATE TABLE Product
    -> (
    ->    ID SMALLINT NOT NULL PRIMARY KEY,
    ->    Color VARCHAR(15) NOT NULL
    -> );
Query OK, 0 rows affected (0.07 sec)

mysql> INSERT INTO Product VALUES (101, 'Red'),
    ->                                  (102, 'red'),
    ->                                  (103, 'RED'),
    ->                                  (104, 'REd'),
    ->                                  (105, 'reD'),
    ->                                  (106, 'Blue'),
    ->                                  (107, 'blue'),
    ->                                  (108, 'BLUE'),
    ->                                  (109, 'BLue'),
    ->                                  (110, 'blUE');
Query OK, 10 rows affected (0.01 sec)
Records: 10  Duplicates: 0  Warnings: 0

mysql> select * from Product;
+-----+-------+
| ID  | Color |
+-----+-------+
| 101 | Red   |
| 102 | red   |
| 103 | RED   |
| 104 | REd   |
| 105 | reD   |
| 106 | Blue  |
| 107 | blue  |
| 108 | BLUE  |
| 109 | BLue  |
| 110 | blUE  |
+-----+-------+
10 rows in set (0.00 sec)


*/

Drop table Product;

CREATE TABLE Product
(
   ID SMALLINT NOT NULL PRIMARY KEY,
   Color VARCHAR(15) NOT NULL
);


INSERT INTO Product VALUES (101, 'Red'), 
                                 (102, 'red'), 
                                 (103, 'RED'), 
                                 (104, 'REd'), 
                                 (105, 'reD'),
                                 (106, 'Blue'), 
                                 (107, 'blue'), 
                                 (108, 'BLUE'), 
                                 (109, 'BLue'), 
                                 (110, 'blUE');
select * from Product;
           
         
    
  








Related examples in the same category

1.VARCHAR(n) character string with variable length, maximum 65,535 characters
2.Varchar type column with collate latin1_german1_ci
3.CHAR and VARCHAR types are searched case insensitively, unless you use the BINARY keyword.
4.Not null varchar column
5.Nullable varchar column
6.Compare varchar value