SSDT – Error SQL70001 This statement is not recognized in this context-摘自网络
March 28, 2013 — arcanecode
One of the most common errors I get asked about when using SQL Server Data Tools (SSDT) Database Projects is the error “This statement is not recognized in this context”. This is actually a pretty simple error to fix.
Envision this scenario. You have a simple table:
CREATE TABLE [dbo].[Test] ( [Id] INT IDENTITY NOT NULL PRIMARY KEY , [SomeData] NVARCHAR(20) NOT NULL )
Great. So then you want to have a post deployment script which will populate it with some default value. Because we are following best practices we creating a post deployment script which then calls the script to populate the default data.
:r .\InsertSomeData.sql
Then we have the script InsertSomeData.sql itself:
INSERT INTO [dbo].[Test] ([SomeData]) VALUES (‘Arcane Code’)
After inserting the code, or doing a build, you get this ugly error pop up in the error window:
So what happened? Well, when you went to insert the script you had these options in the dialog:
If you aren’t careful, you could accidentally pick the “Script (Build)” option (highlighted in blue). This option attempts to compile and run the code as DDL (Data Definition Language, the T-SQL syntax which creates tables, indexes, etc.) syntax. Things like Insert statements though are considered DML (Data Manipulation Language) code, and aren’t eligible to be compiled as part of the project. This is what generates the “This statement is not recognized in this context” error. You are essentially putting DML code where only DDL is allowed.
But don’t despair, this is extremely simple to fix. In SSDT, simply bring up the Properties dialog for the SQL script (click in the SQL script, then View, Properties in the menu). Pick the Build Action property, and change it to None.
And that’s it, the error “SQL70001 This statement is not recognized in this context” should now vanish from your error list.
相关文章
- 网络三张表:ARP表, MAC表, 路由表,实现你的网络自由!!
- 神经网络与机器学习 笔记—核方法和径向基函数网络(上)
- win10报错[nltk_data] Error loading punkt: <urlopen error [Errno 11004] [nltk_data] getaddrinfo fai
- Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.
- 基于UNet+网络进行细胞图像识别与分割
- 零基础入门深度学习(五):长短时记忆网络
- Error while trying to retrieve text for error ORA-12705
- Error:java: Compilation failed: internal java compiler error 解决办法
- Error C1189 #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll
- Python网络爬虫 - 2. Beautiful Soup小试牛刀
- Error:java: Compilation failed: internal java compiler error 解决办法
- Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'event read from binlog did not pass crc check; the first event
- 检测电脑是否连接网络
- 记一次网络质量原因导致接口调用超时的调查过程
- idea中完美解决Error:java: Compilation failed: internal java compiler error的问题
- 【转】VMware虚拟机三种网络模式超详解
- 使用WIF实现单点登录Part III —— 正式实战 -摘自网络
- List使用Foreach 修改集合时,会报错的解决方案 (Error: Collection was modified; enumeration operation may not execute. ) - 摘自网络
- 瞻博网络全球报告:多数企业高管未做好应对数字颠覆的准备
- Java网络编程之Netty
- 网络库libevent、libev、libuv对比