如何删除sql server 中 列的默认值

下面代码说明了如何删除  psColumn 列的默认值

string  vsSql = select sys.default_constraints.name from sys.columns ,sys.default_constraints
                            where parent_object_id = sys.columns.object_id  and sys.columns.column_id = parent_column_id
                            and sys.columns.name = '" + psColumn + "'";


                    DataSet ds = Query(vsSql);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
第一步找到 
                        string vsName = dsCon.Tables[0].Rows[0]["name"].ToString();
第二步删除
                        Exec("alter table tbjcsj drop CONSTRAINT " + vsName);
                    }

转载于:https://www.cnblogs.com/sunfq/archive/2007/12/17/999543.html

你可能感兴趣的:(如何删除sql server 中 列的默认值)