真正简单的IF x CREATE TABLE语句的语法错误

时间:2014-10-30 19:52:45

标签: sql sql-server tsql

我正在sql server 2008中写一个tic tac toe游戏。 这就是我到目前为止所做的:

print '
==========================================================
Tic Tac Toe - SQL Server 2008 - My Name - 10/30/2014
==========================================================
To insert an ''X'', type EXEC pMakeMove row, column, skip.
Row and column must both be between 1 and 3 or you will 
automatically forfeit your move. skip can be either 1 or 
0, with 1 specifying that you''d like to skip your turn. 

You will always start first, unless you decide to skip 
your first turn. You will always be ''X'' and the PC will 
always be ''O''.

When you make a move, the PC will automatically make a 
move as well, the game will check for a winner after 
each of these moves.

After each move, the game board is displayed.

On a winning move, the game board is displayed, a
message is displayed, and the board is cleared.
'

if not exists (
        select * 
        from INFORMATION_SCHEMA.TABLES 
        where TABLE_SCHEMA = 'dbo' 
        and TABLE_NAME = 'TicTacToe')
begin
    create table TicTacToe
    (
        [row] as int,
        [1] as bit,
        [2] as bit,
        [3] as bit
    )

    insert into TicTacToe (row,[1],[2],[3]) values (1,null,null,null),(2,null,null,null),(3,null,null,null)
end
else
begin
    update TicTacToe set [1]=null,[2]=null,[3]=null
end

这是我得到的随机错误:

Msg 102, Level 15, State 1, Line 31
Incorrect syntax near ')'.

我没有看到任何明显的原因。

这迫使我添加更多细节。这就是你需要的所有细节。 StackOverflow有时是愚蠢的。

2 个答案:

答案 0 :(得分:3)

将您的陈述改为:

create table TicTacToe
(
    row int,
    [1] bit,
    [2] bit,
    [3] bit
)

定义表时,您无法写as。这是一个相对常见的错误,解析器对它没有多大帮助。

答案 1 :(得分:1)

在[]中附加row保留关键字,但也缺少;

同时删除

create table TicTacToe
(
    [row]  int,
    [1]  bit,
    [2]  bit,
    [3]  bit
);