Judge whether a column exists in a table

Posted on 2006-06-08 12:28  C#Hunter  阅读(335)  评论(3编辑  收藏  举报

if not exists( select 1 from dbo.syscolumns s
where name ='yourColumn'
and id = object_id(N'YourTable'))
begin
alter table YourTable add yourColumn ColumnType
end

Copyright © 2024 C#Hunter
Powered by .NET 8.0 on Kubernetes