2016-06-28 62 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