簡體   English   中英

為 varchar 列指定默認值 225 個空格

[英]Specify a default of 225 spaces for a varchar column

我正在嘗試使用下表將文字游戲的 15 x 15 個字母板保存為 MySQL 5.6 數據庫中的 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)
);

不幸的是,這會返回一個錯誤:

ERROR 1064 (42000):您的 SQL 語法有錯誤; 檢查與您的 MySQL 服務器版本相對應的手冊,了解在“space(225))”附近使用的正確語法

我只是想用 15 x 15 個空格初始化游戲板 - 並且想在以后每次移動時修改該板。

你能推薦我一個更好的方法嗎?

您不能使用函數作為默認值:

我可以在 MySql 中使用函數作為默認值嗎?

所以你可以將你的默認值定義為一個字符串:

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

或者您可以使用觸發器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM