本文介紹了drop table 附近的語法不正確的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想編寫以下 SQL 查詢,但是 drop table @temp
和創建表@temp
,這是為什么呢?(使用 SQL Server 2015)
I want to write the following SQL query, however there are incorrect syntax errors with drop table @temp
and
create table @temp
, why is it that? (Using SQL Server 2015)
DECLARE @temp NVARCHAR(10)
SET @temp='sth'
IF OBJECT_ID(@temp, 'U') IS NOT NULL
DROP TABLE @temp
CREATE TABLE @temp
推薦答案
要回答 WHY 的問題,這是很久以前的句法約定.
DROP 語句是這樣的:
To answer the question WHY, it is a syntactic convention from days long past.
The DROP statement goes like this:
DROP TABLE MyTable
和不是像這樣:
DROP TABLE 'MyTable'
MyTable
是一個標識符,SQL 中的標識符不加引號.并且因為它不使用引號,所以它不接受變量.
MyTable
is an identifier, and identifiers in SQL are not quoted. And because it uses no quotes, it does not accept variables.
也與 WHERE
子句比較:
WHERE MyCol = 'abc'
-- MyCol is not quoted because it is an identifier.
-- 'abc' is quoted because it is a value, and so it can be replaced by a variable.
這篇關于drop table 附近的語法不正確的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!