C # When creating a table, I get an "incorrect syntax" error if the name of my column / field contains the division "-"

Below is a snippet of my code, when the table name contains a hyphen, I get the error below. How can i fix this? Thanks for the help.

alt text http://img109.imageshack.us/img109/148/createtable.png

ex = {"ERROR [42000] [Microsoft] [SQL Server ODBC driver] [SQL Server] Line 1: invalid syntax next to '-'." }

+3
source share
6 answers

Use []around the column name:

CREATE TABLE [test2] 
(cn VarChar(1024) NULL,
 [tutor-id] VarChar(1024) NULL)

Or it is advisable to stick to column names that do not require special handling ...

, , , .

+6

[tutor-id]

+3

, , [tutor-id], tutor-id, tutorId - , .

+3

SQL . tutor : [tutor-id]

+2

[].

+2

Try:

CREATE [test2] (  [cn] varchar (1024) NULL,  [tutor-id] varchar (1024) NULL )

+1

Source: https://habr.com/ru/post/1725848/


All Articles