比如 要插入2条是
INSERT INTO dongyt_student (学号,姓名)
 VALUES (123, 'ghjghj')
INSERT INTO dongyt_student (学号,姓名)
 VALUES (124, 'dfzgfdg')每次都要写INSERT INTO dongyt_student (学号,姓名)
能不能只用一条 INSERT INTO 后面跟着N条 VALUES

解决方案 »

  1.   

    --创建表student
    create table student([id] int,[name] varchar(100))
    go--多次插入数据,修改@id,@name 的值并执行以下语句
    declare @id int
    declare @name varchar(100)
    set @id=124
    set @name='ghjghj'
    insert into student select @id,@name
    select * from student--drop table student
      

  2.   

    create table student([id] int,[name] varchar(100))
    go
    insert into student
    select 123,'liping'
    union all select 124,'pingli'
    union all select 125,'addd'
    union all select 126,'assss'
    --等等可以很多
      

  3.   

    --如果有选择性的插入多行可以:
    --建立测试环境
    Create Table tblTest
    (
        TestID    Numeric(18,0)    IDENTITY(1,1)    NOT NULL,
        TestName    Varchar(50)    NOT NULL,
        TestStatus    Int    Default(1)    NULL,
        TestCreateDate    Datetime    Default (getdate())    NULL
    )
    --测试插入
    Insert tblTest
    (
        TestName
    )
    (
        Select 'tn1'
        Union All Select 'tn2'
        Union All Select 'tn3'
    )
    --查询测试表
    Select * From tblTest
    --删除测试环境
    Drop Table tblTest
      

  4.   

    NSERT INTO dongyt_student (学号,姓名)
    select 123, 'ghjghj'
    union all select 124, 'dfzgfdg'