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
a0
b0
c0
d0
e0
[解决办法]
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
a0
b0
c0
d0
e0
f 2
h 0
[解决办法]
在给表加Default的约束的时候,在语句最后加上With Values就可以了。