sqlserver怎样判断查询出来的表里 某列是否存在

2024-12-31 06:01:06
推荐回答(1个)
回答1:

类似下面例子,判断不存在字段则增加
IF NOT EXISTS (SELECT a.name FROM syscolumns a,sysobjects b
WHERE a.id=b.id
AND LTRIM(a.name)='col_name' AND LTRIM(b.name)='tablename')
ALTER TABLE [tablename] ADD [col_name] char(3) NULL
GO