插入表格

时间:2012-06-25 09:35:42

标签: sql sql-server-2008

我只想在表格中添加一些数据,但收到错误:

Msg 110, Level 15, State 1, Line 1
There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

这是我正在使用的

INSERT INTO dbo.ReModalities
(ModalityId, Name, Description)
VALUES
(
    1,'A','A.',
    2,'B','B.'
);

这可以让您了解表格列

INSERT INTO [XXX].[dbo].[ReModalities]
           ([ModalityId]
           ,[Name]
           ,[Description])
     VALUES
           (<ModalityId, int,>
           ,<Name, nvarchar(64),>
           ,<Description, nvarchar(256),>)
GO

另外我想知道是否有办法可以避免输入ID(表格有PK,所以应该自动创建)非常感谢!

1 个答案:

答案 0 :(得分:5)

values语句的每一行都应括在括号中。尝试:

VALUES
    (1,'A','A.'),
    (2,'B','B.');

如果ID具有默认值或identity,则可以省略它:

insert  dbo.ReModalities
        (Name, Description)
values  ('A','A.'),
        ('B','B.');
相关问题