2016-06-28 45 views
-1

我從來沒有使用SQL Servre,所以這對我來說是完全陌生的。插入行錯誤,錯誤的語法靠近'<'

我有以下插入語句:

INSERT INTO 
    [dbo].[WEB_static_pages]([url], [template], [title], [metadesc],[metakey]) 
VALUES 
    (<url, varchar(255), "test">, 
    <template, varchar(255), "test.php">, 
    <title, nvarchar(255), "test title">, 
    <metadesc, text, "test meta">, 
    <metakey, text, "test meta key">) 
GO 

下有三個 '提示' 警告,儘管在SQL Server Management Studio中:

附近有語法錯誤<' 「和」 VARCHAR是不是一個公認的內置函數名

任何人都可以提出什麼問題在這裏?我如何重新格式化我的陳述以適應SQL Server Management Studio?

+0

不能混淆表的定義和插入表中。在SQL服務器中有很多插入的例子。只需尋找10秒 –

+0

@juergend我努力尋找任何在我的問題中使用的語法,這是SQL Server Management Studio生成的語法,因此我認爲這是我所需要的。 –

回答

1

使用SQL Server插入值時,只需指定要在VALUES子句中插入的實際數據。因此,使用以逗號分隔值列表,你的情況,並在括號包起來:

INSERT INTO [dbo].[WEB_static_pages] 
      ([url] 
      ,[template] 
      ,[title] 
      ,[metadesc] 
      ,[metakey]) 
VALUES (
     'test', 
     'test.php', 
     'test title', 
     'test meta', 
     'test meta key') 
+0

如果將「(雙引號)替換爲'(單引號),會更好。 –

0

重寫它這樣,它應該工作:

INSERT INTO [dbo].[WEB_static_pages] 
      ([url] 
      ,[template] 
      ,[title] 
      ,[metadesc] 
      ,[metakey]) 
    VALUES 
      ('test' 
      ,'test.php' 
      ,'test title' 
      ,'test meta' 
      ,'test meta key') 
GO