mssql sqlserver 添加字段,添加列方法分享


摘要:
下文将讲述如何对一张系统已经存在的表,添加字段



添加字段的方法

alter table [表名称] 
 add [列名] 列类型 default [列默认值] not null 

例:

 create table A (keyId int identity(1,1),name varchar(30))
go
insert into A (name)values('a')
insert into A (name)values('b')
insert into A (name)values('c')
insert into A (name)values('d')
insert into A (name)values('e')
insert into A (name)values('f')
go
/*新增列*/
alter table A 
add name2 varchar(30) default 'test'   ---默认会在新增行数据时,产生默认
go

select * from A 
go
insert into A (name)values('g')
go
select * from A 
go
truncate table A
drop table A 
go