2014-10-30 1 views
0

내가 SQL Server의 박하 사탕 정면 게임을 쓰는 사람을 만드는 경우 :구문 오류 X 이것은 내가 지금까지 무엇을 가지고 2008 년 TABLE 문

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 

그리고 이것은 임의의 오류 I입니다 받는 중 :

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

나는 명백한 이유가 없습니다.

자세한 내용을 추가해야합니다. 그게 정말로 필요한 모든 세부 사항입니다. StackOverflow 때때로 바보입니다.

+1

저는 SQL Server 전문가는 아니지만 문장을 세미콜론으로 끝내지 않아야합니까? – JNevill

+0

@Yuck 괜찮아요. 게임을 작성하는 데 편리합니다. '[] '를 사용하면 문제가되지 않습니다. – KthProg

+0

@JNevill 각 문장 뒤에 세미콜론을 추가 했는데도 여전히 같은 오류가 발생합니다. – KthProg

답변

3

이에 문을 변경 : 당신이 as을 쓸 수 없습니다

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

테이블을 정의 할 때. 비교적 일반적인 실수이며 파서는 그다지 도움이되지 않습니다.

+0

예, 이상하게 들리지 않았습니다. – KthProg

+0

동의하려면 8 분을 기다려야합니다. – KthProg

1

[]의 row 예약 키워드를 포함하고 있습니다.

제거는 또한

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

정말로 유일한 문제는'create' 문에서'as '를 사용하는 것이 었습니다. – Yuck

+0

여전히 같은 오류가 발생합니다. Row는 SQL Server에서 예약어가 아닙니다. – KthProg

+0

@Yuck 당신 말이 맞아요. 대답으로 추가하면 받아 들일 것입니다. 고맙습니다. – KthProg

관련 문제