USE [MK_UboxChs]
GO
/****** Object: Table [dbo].[ACCOUNT_ITEM_TBL] Script Date: 09/21/2010 09:43:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter TABLE [dbo].[ACCOUNT_ITEM_TBL]
alter column UPTIME datetime2 NOT NULL
go
declare @default sysname, @sql nvarchar(max)
-- get name of default constraint
select @default = name
from sys.default_constraints
where parent_object_id = object_id('ACCOUNT_ITEM_TBL')
AND type = 'D'
AND parent_column_id = (
select column_id
from sys.columns
where object_id = object_id('ACCOUNT_ITEM_TBL')
and name = 'NEWTIME'
)
-- create alter table command as string and run it
set @sql = N'alter table ACCOUNT_ITEM_TBL drop constraint ' + @default
exec sp_executesql @sql
go
alter TABLE [dbo].[ACCOUNT_ITEM_TBL]
alter column NEWTIME datetime2 NOT NULL
go
如何drop有default constraint的column - SQL
最新推荐文章于 2021-04-30 09:46:34 发布