USE testdb;CREATETABLEIFNOTEXISTS varchar_test ( s1 VARCHAR(32765) NOT NULL, s2 VARCHAR(32766) NOT NULL) CHARACTERSET'latin1'COLLATE LATIN1_DANISH_CI;
该语句成功创建了表。 但是,如果我们将s1列的长度增加1。
USE testdb;CREATETABLEIFNOTEXISTS varchar_test_2 ( s1 VARCHAR(32766) NOT NULL, -- error s2 VARCHAR(32766) NOT NULL) CHARACTERSET'latin1'COLLATE LATIN1_DANISH_CI;
MySQL将发出错误消息:
Error Code: 1118. 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 BLOBs 0.000 sec
如上所示,行长度太大,所以创建语句失败。
如果插入长度大于VARCHAR列长度的字符串,MySQL将发出错误。 请考虑以下示例:
USE testdb;CREATETABLEitems ( id INTPRIMARY KEY AUTO_INCREMENT, title VARCHAR(3));INSERT INTO items(title)VALUES('ABCD');