- text 长文本类型 适用于存储“较长的文本内容”,比如文章内容。最长可存储65535个字符。 如果还需要存储更长的京本,可以使用 mediumtext (1600万左右)或 longtext (40亿左右)。 设定形式:字段名称 text text 类型的字段不能设置默认值。 text 类型虽然是字符类型,但是不能设置长度!!!
``` mysql> create table article (id int autoincrement primary key, title varchar(100), author varchar(20), content text, pubtime datetime, edittime timestamp); mysql> desc article; +-----------+--------------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+-------------------+-----------------------------+ | id | int(11) | NO | PRI | NULL | autoincrement | | title | varchar(100) | YES | | NULL | | | author | varchar(20) | YES | | NULL | | | content | text | YES | | NULL | | | pubtime | datetime | YES | | NULL | | | edittime | timestamp | NO | | CURRENTTIMESTAMP | on update CURRENTTIMESTAMP | +-----------+--------------+------+-----+-------------------+-----------------------------+
mysql> insert into article (title, author, content, pubtime) values ('文章标题', '张三', '文章内容', '2020-8-8 20:00:00'); mysql> select * from article; +----+--------------+--------+--------------+---------------------+---------------------+ | id | title | author | content | pubtime | edit_time | +----+--------------+--------+--------------+---------------------+---------------------+ | 1 | 文章标题 | 张三 | 文章内容 | 2020-08-08 20:00:00 | 2020-07-06 18:00:54 | +----+--------------+--------+--------------+---------------------+---------------------+
mysql> insert into article (title, author, content, pubtime) values ('文章标题', '李四', '文章内容', now()); mysql> select * from article; +----+--------------+--------+--------------+---------------------+---------------------+ | id | title | author | content | pubtime | edit_time | +----+--------------+--------+--------------+---------------------+---------------------+ | 1 | 文章标题 | 张三 | 文章内容 | 2020-08-08 20:00:00 | 2020-07-06 18:00:54 | | 2 | 文章标题 | 李四 | 文章内容 | 2020-07-06 18:01:54 | 2020-07-06 18:01:54 | +----+--------------+--------+--------------+---------------------+---------------------+ ```
————————————————