【发布时间】:2015-03-18 07:20:26
【问题描述】:
我想在 C# 中的现有表中添加一列,如果它不存在的话。我知道我必须使用“更改表”命令。
但我无法在我的 C# 代码中触发该命令。
我该怎么办?
我正在使用 Visual Studio 2010 和 Sql Server 2008。
【问题讨论】:
-
修正了一些语法和格式,删除了不相关的问候和感谢
标签: c# asp.net .net sql-server database
我想在 C# 中的现有表中添加一列,如果它不存在的话。我知道我必须使用“更改表”命令。
但我无法在我的 C# 代码中触发该命令。
我该怎么办?
我正在使用 Visual Studio 2010 和 Sql Server 2008。
【问题讨论】:
标签: c# asp.net .net sql-server database
这个:
Use [DatabaseName]
Go
if Not exists( Select * from sys.columns As clm
where clm.object_id = OBJECT_ID(N'[TableName]')
And clm.name = N'[ColumnName]'
)
Begin
Alter Table TableName
Add ColumnName DataTypeName
End
【讨论】: