SQL/MySQL/Data Type/Tiny Int
Версия от 13:46, 26 мая 2010; (обсуждение)
Define and use tiny int
/*
mysql> Drop table CDs;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE CDs (
-> CDID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> CDName VARCHAR(50) NOT NULL,
-> Copyright YEAR,
-> NumberDisks TINYINT UNSIGNED NOT NULL DEFAULT 1,
-> NumberInStock TINYINT UNSIGNED,
-> NumberOnReserve TINYINT UNSIGNED NOT NULL,
-> NumberAvailable TINYINT UNSIGNED NOT NULL,
-> CDType VARCHAR(20),
-> RowAdded TIMESTAMP
-> );
Query OK, 0 rows affected (0.09 sec)
mysql> INSERT INTO CDs
-> (CDName, Copyright, NumberDisks, NumberInStock, NumberOnReserve, NumberAvailable, CDType)
-> VALUES
-> ("Blues", 1998, DEFAULT, 4, 1, NumberInStock-NumberOnReserve, "Blues");
Query OK, 1 row affected (0.01 sec)
mysql> select * from CDs;
+------+--------+-----------+-------------+---------------+-----------------+-----------------+--------+---------------------+
| CDID | CDName | Copyright | NumberDisks | NumberInStock | NumberOnReserve | NumberAvailable | CDType | RowAdded |
+------+--------+-----------+-------------+---------------+-----------------+-----------------+--------+---------------------+
| 1 | Blues | 1998 | 1 | 4 | 1 | 3 | Blues | 2005-10-09 09:19:47 |
+------+--------+-----------+-------------+---------------+-----------------+-----------------+--------+---------------------+
1 row in set (0.00 sec)
*/
Drop table CDs;
CREATE TABLE CDs (
CDID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
CDName VARCHAR(50) NOT NULL,
Copyright YEAR,
NumberDisks TINYINT UNSIGNED NOT NULL DEFAULT 1,
NumberInStock TINYINT UNSIGNED,
NumberOnReserve TINYINT UNSIGNED NOT NULL,
NumberAvailable TINYINT UNSIGNED NOT NULL,
CDType VARCHAR(20),
RowAdded TIMESTAMP
);
INSERT INTO CDs
(CDName, Copyright, NumberDisks, NumberInStock, NumberOnReserve, NumberAvailable, CDType)
VALUES
("Blues", 1998, DEFAULT, 4, 1, NumberInStock-NumberOnReserve, "Blues");
select * from CDs;