MySQL - 在 varchar 中存储长度 1000
MySQL - storage in varchar for length 1000
如果我存储长度为 1000 的数据,使用 varchar 是个好主意吗?下面是我的脚本,SR_NOTES 栏是我担心的。我使用 utf8,引擎是 INNODB。例如,使用 TINYTEXT 会更明智吗?我热衷于在不影响性能的情况下创建数据库设计。
CREATE TABLE IF NOT EXISTS SROR (
SROR_ID INT UNSIGNED NOT NULL,
CRAN_ID INT UNSIGNED NOT NULL,
SR_TAGS VARCHAR(250) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
GR_VALUES DECIMAL(4,2), -- 12.25 R
NOTICE_PERIOD SMALLINT UNSIGNED DEFAULT NULL,
C_STATUS VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' DEFAULT 'INACTIVE',
SR_NOTES VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' DEFAULT NULL,
SR_CONTROL VARCHAR(10) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' DEFAULT NULL,
START_DATE DATETIME DEFAULT CURRENT_TIMESTAMP,
LAST_UPDATE DATETIME ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (SROR_ID, CRAN_ID),
INDEX idx_SROR_id1 (SROR_ID ASC),
INDEX idx_SROR_id2 (CRAN_ID ASC),
CONSTRAINT fk_SROR_C1
FOREIGN KEY (CRAN_ID)
REFERENCES R_CONFIG (CRAN_ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
考虑使用不同的数据类型,例如 TEXT
最多可以存储 65535 个字符。存储笔记的好选择。
参见:
What is the MySQL VARCHAR max size?
如果我存储长度为 1000 的数据,使用 varchar 是个好主意吗?下面是我的脚本,SR_NOTES 栏是我担心的。我使用 utf8,引擎是 INNODB。例如,使用 TINYTEXT 会更明智吗?我热衷于在不影响性能的情况下创建数据库设计。
CREATE TABLE IF NOT EXISTS SROR (
SROR_ID INT UNSIGNED NOT NULL,
CRAN_ID INT UNSIGNED NOT NULL,
SR_TAGS VARCHAR(250) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' NOT NULL,
GR_VALUES DECIMAL(4,2), -- 12.25 R
NOTICE_PERIOD SMALLINT UNSIGNED DEFAULT NULL,
C_STATUS VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' DEFAULT 'INACTIVE',
SR_NOTES VARCHAR(1000) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' DEFAULT NULL,
SR_CONTROL VARCHAR(10) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci' DEFAULT NULL,
START_DATE DATETIME DEFAULT CURRENT_TIMESTAMP,
LAST_UPDATE DATETIME ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (SROR_ID, CRAN_ID),
INDEX idx_SROR_id1 (SROR_ID ASC),
INDEX idx_SROR_id2 (CRAN_ID ASC),
CONSTRAINT fk_SROR_C1
FOREIGN KEY (CRAN_ID)
REFERENCES R_CONFIG (CRAN_ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_unicode_ci;
考虑使用不同的数据类型,例如 TEXT
最多可以存储 65535 个字符。存储笔记的好选择。
参见: What is the MySQL VARCHAR max size?