Mysql 为varchar列指定默认值225个空格

Mysql 为varchar列指定默认值225个空格,mysql,mysql-5.6,Mysql,Mysql 5.6,我正试图使用下表,在MySQL 5.6数据库中将15×15个字母的文字游戏板保存为225个字符的字符串: create table games ( gid integer primary key auto_increment, player1 integer references users(uid) on delete cascade, player2 integer references users(uid) on delete cascade

我正试图使用下表,在MySQL 5.6数据库中将15×15个字母的文字游戏板保存为225个字符的字符串:

create table games (
        gid integer primary key auto_increment,
        player1 integer references users(uid) on delete cascade,
        player2 integer references users(uid) on delete cascade,
        stamp1 integer not null default 0,
        stamp2 integer not null default 0,
        letters1 varchar(7) not null,
        letters2 varchar(7) not null,
        letters varchar(116) not null,
        board varchar(225) not null default space(225)
);
不幸的是,这将返回一个错误:

错误1064(42000):您的SQL语法有错误;检查 与右边的MySQL服务器版本相对应的手册 使用“空格(225))”附近的语法

我只是想用15 x 15的空格来初始化游戏板,并且想在以后的每一步中修改该板


您能推荐一种更好的方法吗?

您不能将函数用作默认值:

因此,您可以将默认值定义为字符串:

board varchar(225) not null default ".................up to 225...."

或者您可以使用触发器。

可以使用char(255),这将创建一个固定大小的列。请参阅您是否建议
板字符(225)不为空默认值“”
?是。无法确定默认值是多少,但mysql在插入时将使用最多255个空格填充值,在检索时删除空格(您可以让它保留空格,请参见上面的链接)
default子句为列指定默认值。除了一个例外,默认值必须是常量;它不能是函数或表达式。
。我明白了,谢谢。。。我只是对在我的
数据库创建.sql
中写出这么长的字符串感到不安(因为很难发现缺少的空白)。我希望我能像你一样说
'>x225
Perl@AlexanderFarber我同意,像空间(225)这样的函数是非常清楚的,而空间序列不是。。。但我认为没有其他解决办法,只有一个触发器。