简体   繁体   English

在SQL Server Management Studio中执行查询

[英]Execute query in SQL Server Management Studio

This very simple query I am trying to execute in SQL Server Management Studio. 我正在尝试在SQL Server Management Studio中执行此非常简单的查询。 But it gives error: 但是它给出了错误:

CREATE TABLE `contact` (
  `contact_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  `email` varchar(45) NOT NULL,
  `address` varchar(45) NOT NULL,
  `telephone` varchar(45) NOT NULL,
  PRIMARY KEY (`contact_id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8

Error is: 错误是:

Msg 102, Level 15, State 1, Line 3 Msg 102,第15级,状态1,第3行
Incorrect syntax near '`'. '`'附近的语法不正确。

I also tried by replacing 我也尝试过更换 with '` but still no help with '`但还是没有帮助

The backtick ( ` ) character is only used for MySql. 反引号( ` )字符仅用于MySql。 It's not standard. 这不是标准的。 Sql Server is a completely different animal. Sql Server是完全不同的动物。 You need to use square-brackets ( [ and ] -- also not standard) to enclose table and column names with Sql Server. 您需要使用方括号( [] -也非标准)将表和列名包含在Sql Server中。 Sql Server also supports double quotes ( " ), which are part of the SQL Standard, but for some reason less-common. Sql Server还支持双引号( " ),这是SQL标准的一部分,但由于某种原因不太常见。

While I'm at it, the ENGINE and AUTO_INCREMENT, and CHARSET clauses are also MySql-specific. 当我在使用它时,ENGINE和AUTO_INCREMENT以及CHARSET子句也是MySql特有的。

Try this: 尝试这个:

CREATE TABLE contact (
  contact_id int IDENTITY(25,1) NOT NULL PRIMARY KEY,
  [name] varchar(45) NOT NULL,
  email varchar(45) NOT NULL,
  "address" varchar(45) NOT NULL,
  telephone varchar(45) NOT NULL
)

in tsql 在tsql中

CREATE TABLE contact (
  contact_id int identity(0,25) NOT NULL,
  name nvarchar(45) NOT NULL,
  email nvarchar(45) NOT NULL,
  address nvarchar(45) NOT NULL,
  telephone nvarchar(45) NOT NULL

  CONSTRAINT contact_PK PRIMARY KEY (contact_id)
)

You can't specify engine. 您无法指定引擎。

identity(0,25) means initial value = 0, increment = 25 identity(0,25)表示初始值= 0,增量= 25

You don't specify character set for the table, you can declare individual columns as varchar or nvcarchar -- the n stands for unicode. 您无需为表指定字符集,可以将各个列声明为varchar或nvcarchar - n代表unicode。 You can also specify a collation sequence for each column. 您还可以为每列指定排序规则序列。

If you want a column name that is irregular (keyword, embedded space, etc.) you quote the column name as [column name] -- don't use irregular column names if you have a choice, it just makes things a pain to use. 如果您要使用不规则的列名(关键字,嵌入的空间等),请将该列名引用为[column name]-如果可以选择,则不要使用不规则的列名,这会使您很痛苦采用。

Try like this: 尝试这样:

CREATE TABLE contact (
  contact_id[int] IDENTITY(1,1) NOT NULL,
  name varchar(45) NOT NULL,
  email varchar(45) NOT NULL,
  address varchar(45) NOT NULL,
  telephone varchar(45) NOT NULL,
  PRIMARY KEY (contact_id)
) 

Hope this may help you. 希望这对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM