--以表名bpr000t 欄位名 level1 舉例說明新增及修改預設值約束的方法步驟
--1.檢視表bpr000t的level1欄位是否有預設值約束
select a.name as 使用者表,b.name as 欄位名,d.name as 字段預設值約束
from sysobjects a
inner join syscolumns b on (a.id = b.id)
inner join syscomments c on (b.cdefault = c.id)
inner join sysobjects d on (c.id = d.id)
where a.name = 'bpr000t' and b.name = 'level1'
--2.如果有預設值約束,刪除對應的預設值約束
declare @tablename varchar(30)
declare @fieldname varchar(50)
declare @sql varchar(300)
set @tablename = 'bpr000t'
set @fieldname = 'level1'
set @sql=''
select @sql = @sql + 'alter table ['+ a.name + '] drop constraint [' + d.name + ']'
from sysobjects a
inner join syscolumns b on (a.id = b.id)
inner join syscomments c on (b.cdefault = c.id)
inner join sysobjects d on (c.id = d.id)
where a.name = @tablename and b.name = @fieldname
exec(@sql)
--3.新增預設值約束
alter table bpr000t add default ('1') for level1 with values
SQL修改字段預設值方法
declare tablename varchar 30 declare fieldname varchar 50 declare sql varchar 300 set tablename dncdeta1 set fieldname description set sql select sql ...
修改表的預設值
乙個表中所有字段繫結約束的值 select name from sysobjects where object id initialization parent obj and xtype d 修改表中某乙個欄位的預設值 1 首先找出該欄位繫結約束的值 set tablename 表名 set fi...
方法引數 預設值 Python引數的預設值陷阱!
今日分享 引數的預設值陷阱 下面定義的函式f,其引數d是乙個預設引數,且為字典型別 def f a,d print f a print f d do some process return d 最後返回字典d,下面呼叫函式f ret dict f 1 第二個引數d使用預設值 ret dict b 2...