日期:2014-05-18  浏览次数:20417 次

SQL语句插入列!
怎么样在使用SQL语句向一个表插入一个int列的时候,同时将该表对应的该列值设置为0?

------解决方案--------------------
设置默认值为 '0 ' 就可以了。
------解决方案--------------------
create table a(name varchar(10),id int default 0)
insert into a(name)
select 'a '
union select 'b '
union select 'c '
union select 'd '
union select 'e '

select * from a
drop table a
----
name id
a 0
b 0
c 0
d 0
e 0

------解决方案--------------------
ALTER TABLE tablename ADD 列名 int DEFAULT 0
------解决方案--------------------
现有的数据
update 一下
------解决方案--------------------
只能update,没有别的办法
------解决方案--------------------
ALTER TABLE tablename ADD 列名 int not null DEFAULT 0
ALTER TABLE tablename ADD 列名 int DEFAULT 0

------解决方案--------------------
create table a(name varchar(10),id int default 0)
insert into a(name)
select 'a '
union select 'b '
union select 'c '
union select 'd '
union select 'e '
insert into a values( 'f ',2)
insert into a(name) values( 'h ')
go
select * from a
----
name id
a 0
b 0
c 0
d 0
e 0
f 2
h 0
------解决方案--------------------
在给表加Default的约束的时候,在语句最后加上With Values就可以了。