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


本文转载:CSDN博客