国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

MySQL中數(shù)據(jù)類型的驗(yàn)證

2024-07-24 12:45:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

CHAR

char (M) M字符,長(zhǎng)度是M*字符編碼長(zhǎng)度,M最大255。

驗(yàn)證如下:

mysql> create table t1(name char(256)) default charset=utf8;ERROR 1074 (42000): Column length too big for column 'name' (max = 255); use BLOB or TEXT insteadmysql> create table t1(name char(255)) default charset=utf8;Query OK, 0 rows affected (0.06 sec)mysql> insert into t1 values(repeat('整',255));Query OK, 1 row affected (0.00 sec)mysql> select length(name),char_length(name) from t1;+--------------+-------------------+| length(name) | char_length(name) |+--------------+-------------------+| 765 | 255 |+--------------+-------------------+1 row in set (0.00 sec)

VARCHAR

VARCHAR(M),M同樣是字符,長(zhǎng)度是M*字符編碼長(zhǎng)度。它的限制比較特別,行的總長(zhǎng)度不能超過(guò)65535字節(jié)。

mysql> create table t1(name varchar(65535));ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBsmysql> create table t1(name varchar(65534));ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBsmysql> create table t1(name varchar(65533));ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBsmysql> create table t1(name varchar(65532));Query OK, 0 rows affected (0.08 sec)

注意,以上表的默認(rèn)字符集是latin1,字符長(zhǎng)度是1個(gè)字節(jié),所以對(duì)于varchar,最大只能指定65532字節(jié)的長(zhǎng)度。

如果是指定utf8,則最多只能指定21844的長(zhǎng)度

mysql> create table t1(name varchar(65532)) default charset=utf8;ERROR 1074 (42000): Column length too big for column 'name' (max = 21845); use BLOB or TEXT insteadmysql> create table t1(name varchar(21845)) default charset=utf8;ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBsmysql> create table t1(name varchar(21844)) default charset=utf8;Query OK, 0 rows affected (0.07 sec)

注意:行的長(zhǎng)度最大為65535,只是針對(duì)除blob,text以外的其它列。

mysql> create table t1(name varchar(65528),hiredate datetime) default charset=latin1;ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBsmysql> create table t1(name varchar(65527),hiredate datetime) default charset=latin1;Query OK, 0 rows affected (0.01 sec)
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新安县| 栾川县| 衡山县| 达州市| 内乡县| 徐汇区| 双辽市| 聊城市| 拜泉县| 陇南市| 中山市| 林西县| 桂东县| 乐山市| 麻栗坡县| 淮北市| 年辖:市辖区| 镇宁| 白沙| 休宁县| 芒康县| 巴中市| 彭阳县| 利辛县| 邻水| 武定县| 冀州市| 溆浦县| 宁南县| 峨边| 阳曲县| 阳泉市| 大同市| 那坡县| 辰溪县| 望谟县| 南木林县| 拉孜县| 盖州市| 青田县| 汕头市|