sql  中一次插入多条语句  insert into 表
select   ***  union  
select *** 问  如果在这些列里如果在创建表的时候有默认的 default  该如何写?  能用default吗?请看清题目再解答

解决方案 »

  1.   

    create table kkkk(id int,name  nvarchar(20) default '***')
    goinsert kkkk(id)
    select  1
    union all select 2select * from kkkk/*
    id name
    1 ***
    2 ***
    */
      

  2.   

    insert biao(c1,c2)默认值列不写
    select 1,2
    union all
    select 3,4
      

  3.   

    create table aa
    (
       aid int identity(1,1) primary key,
       asex varhcar(2) default '男',)
    insert into aa values(default)  ---正确
    insert into aa 
    select default union
    select '女'  -- 错误
    --问  这里为什么是错误的? 
      

  4.   

    就是default 那列不用插值啦?
      

  5.   


    create table aa
    (
       aid int identity(1,1) primary key,
       asex varchar(20) default '男',
       idx varchar(200))
     insert into aa(idx)
    select 'abc'
     union
    select 'def'  select * from aa
    /*
    aid         asex                 idx
    ----------- -------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1           男                    abc
    2           男                    def(2 行受影响)*/
      

  6.   

    [code=SQL]--SELECT ... UNION ALL SELECT...语句里面不能用DEFAULT,
    --只有用values里面才能用Default插入默认值!
    --呵呵:
    [CREATE TABLE Detail(bus_index INT DEFAULT 44 NOT NULL, time INT DEFAULT 55, number INT);
    INSERT INTO Detail(bus_index, time, number)
    values(22,DEFAULT, 888)/code]
      

  7.   

    ]--SELECT ... UNION ALL SELECT...语句里面不能用DEFAULT, 
    --只有用values里面才能用Default插入默认值! 
    --呵呵: 
    [CREATE TABLE Detail(bus_index INT DEFAULT 44 NOT NULL, time INT DEFAULT 55, number INT); 
    INSERT INTO Detail(bus_index, time, number) 
    values(22,DEFAULT, 888)
      

  8.   

    --SELECT ... UNION ALL SELECT...语句里面不能用DEFAULT, 
    --只有用values里面才能用Default插入默认值! 
    --呵呵: 
    [CREATE TABLE Detail(bus_index INT DEFAULT 44 NOT NULL, time INT DEFAULT 55, number INT); 
    INSERT INTO Detail(bus_index, time, number) 
    values(22,DEFAULT, 888)/
      

  9.   

    insert into aa(idx)---这里如果不写列名字呢?
    select 'abc'
     union
    select 'def'  
      

  10.   

    SET IDENTITY_INSERT
    允许将显式值插入表的标识列中。语法
    SET IDENTITY_INSERT [ database.[ owner.] ] { table } { ON | OFF }先ON再OFF吧
    insert into 表 (ID) select  1 union  
    select 2
      

  11.   

    楼大,这是语法,只能写在values里,而且values不能和select 一起用(这个可以查select的语法)
    如果非用,需要请微软开发一下INSERT 
        [ TOP ( expression ) [ PERCENT ] ] 
        [ INTO] 
        { <object> | rowset_function_limited 
          [ WITH ( <Table_Hint_Limited> [ ...n ] ) ]
        }
    {
        [ ( column_list ) ] 
        [ <OUTPUT Clause> ]
        { VALUES ( { DEFAULT | NULL | expression } [ ,...n ] ) 
        | derived_table 
        | execute_statement 
        } 

      

  12.   

    狂晕哦 既然在 insert into  table  
    select   .... union 
    select  
    不可以用deault  
    真是见鬼,微软垃圾。。