create table kkkk(id int,name nvarchar(20) default '***') goinsert kkkk(id) select 1 union all select 2select * from kkkk/* id name 1 *** 2 *** */
insert biao(c1,c2)默认值列不写 select 1,2 union all select 3,4
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 '女' -- 错误 --问 这里为什么是错误的?
就是default 那列不用插值啦?
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 行受影响)*/
[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]
]--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)
--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)/
insert into aa(idx)---这里如果不写列名字呢? select 'abc' union select 'def'
SET IDENTITY_INSERT 允许将显式值插入表的标识列中。语法 SET IDENTITY_INSERT [ database.[ owner.] ] { table } { ON | OFF }先ON再OFF吧 insert into 表 (ID) select 1 union select 2
goinsert kkkk(id)
select 1
union all select 2select * from kkkk/*
id name
1 ***
2 ***
*/
select 1,2
union all
select 3,4
(
aid int identity(1,1) primary key,
asex varhcar(2) default '男',)
insert into aa values(default) ---正确
insert into aa
select default union
select '女' -- 错误
--问 这里为什么是错误的?
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 行受影响)*/
--只有用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]
--只有用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)
--只有用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)/
select 'abc'
union
select 'def'
允许将显式值插入表的标识列中。语法
SET IDENTITY_INSERT [ database.[ owner.] ] { table } { ON | OFF }先ON再OFF吧
insert into 表 (ID) select 1 union
select 2
如果非用,需要请微软开发一下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
}
}
select .... union
select
不可以用deault
真是见鬼,微软垃圾。。