sql中判断表中是否存在某个字段并添加或删除


--判断表中是否存在这个字段,不存在就新增
if not exists(select * from sys.columns where name='字段名称' and [object_id]=object_id(N'表名'))
begin
 alter table 表名 add 字段名称 money;
end
GO

--判断表中是否存在这个字段,存在就删除
if exists(select * from sys.columns where name='字段名称' and [object_id]=object_id(N'表名'))
begin
 ALTER TABLE 表名 DROP COLUMN 字段名称;
end
GO

猜你喜欢

转载自blog.csdn.net/q1923408717/article/details/115123325