SQL/MySQL/Data Type/Varchar — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 10:16, 26 мая 2010

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;