SQL删除带有默认值的列

DECLARE @name VARCHAR(100);
SELECT @name = b.name
FROM syscolumns a,
     sysobjects b
WHERE a.id = OBJECT_ID('EMS_Event') --tableName
      AND b.id = a.cdefault
      AND a.name = 'RequiredIndlicativeCount'--column name
      AND b.name LIKE 'DF%';

EXEC ('alter table EMS_Event drop constraint ' + @name); --EMS_Event -->tablenaem
ALTER TABLE EMS_Event DROP COLUMN RequiredIndlicativeCount;
 

sql添加表字段描述添加默认值删除字段 //删除表 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[JHCRM_Report_ss]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [JHCRM_Report_ss] //添加表 if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) create table [Table1] ([col1] int,[col2] int) //添加字段 if not exists( select * from syscolumns where syscolumns.[name]='FNewObjectEnd' and syscolumns.[id]=(select id from dbo.sysobjects where id=object_id(N'[dbo].[jsc_financial]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) ) ALTER TABLE jsc_financial ADD FNewObjectEnd int--NULL --添加先用项目结项数 go EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'先用项目结项数' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'jsc_financial', @level2type=N'COLUMN',@level2name=N'FNewObjectEnd' if not exists( select * from syscolumns where syscolumns.[name]='Record_Money' and syscolumns.[id]=(select id from dbo.sysobjects where id=object_id(N'[dbo].[JHCRM_Resource_Record_Main]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) ) ALTER TABLE JHCRM_Resource_Record_Main ADD Record_Money numeric(12, 2)--NULL --资源费用 go EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'资源费用' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'JHCRM_Resource_Record_Main', @level2type=N'COLUMN',@level2name=N'Record_Money' //删除字段 if not exists( select * from syscolumns where syscolumns.[name]=table_Name and syscolumns.[id]=(select id from dbo.sysobjects where id=object_id(N'[dbo].[tableName]')" and OBJECTPROPERTY(id, N'IsUserTable') = 1) ) ALTER TABLE table_Name DROP COLUMN tableName
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值