Records 3 Duplicates 0 Warnings 2
mysql>
SELECT * FROM mytime;+----+---------------------+
| id | changetime |
+----+---------------------+
| 1 | 0000-00-00 00:00:00 |
| 2 | 2006-07-16 01:02:03 |
| 3 | 2006-07-16 01:05:24 |
+----+---------------------+
3 rows inset sec)
Note how the current time is stored
when we ask to insert a NULL
value. Now, let’s change the id for the first row:
mysql>
UPDATE mytime SET id WHERE id=1;Query OK, 1 row affected (0.08 sec)
Rows matched 1 Changed 1 Warnings 0
mysql>
SELECT * FROM mytime;+----+---------------------+
| id | changetime |
+----+---------------------+
| 4 | 2006-07-16 01:05:42 |
| 2 | 2006-07-16 01:02:03 |
| 3 | 2006-07-16 01:05:24 |
+----+---------------------+
3 rows inset sec)
As you can seethe timestamp is updated to the current timestamp.
There are other variations on how you can control which
column updates automatically, but if you stick to the previous steps, you’ll get the behavior you want. You can find more examples of using timestamps
later in The Sample MusicDatabase.”
CHAR[(
width)]
The most commonly used string type.
CHAR
stores a fixed-length string (such as a name, address, or city)
of length width. If a
widthis not provided,
CHAR(1)
is assumed.
The maximum value of widthis 255. With MySQL versions between and 5.0.2, MySQL accepts values greater than 255 and silently changes the
CHAR
type
to the smallest TEXT
type that is suitable we discuss the
TEXT
type later in this section.
You can in fact define a special CHAR) NULL
column that takes up only one bit of storage. This provides two handy features. First, it allows you to include a dummy column in a table that doesn’t do anything (which might be useful as a placeholder
fora future feature, or to be backward-compatible with an old application. Second, it allows you to store one of two values
NULL
or the empty string ''
, giving you very compact storage of binary (Boolean) values. To help
you understand this better, let’s create a table with a
CHAR(0)
field, and an id field to help differentiate between entries:
Share with your friends: