我从这个脚本创建了一个表。数据库是分区的。
print 'Create Table - tenant_Import'
go
create table tenant_Import
(
Import_Data_Id bigint not null identity(100000000000000, 1),
Audit_Login_Id bigint not null default 0,
Tenant_Id bigint not null,
Tenant_Partition bigint not null,
Map_Id bigint not null,
Filename nvarchar(500) not null,
DataFile varbinary(max) not null,
Status int not null,
DateInserted datetime not null DEFAULT GETDATE(),
DateProcessed datetime null
)
on partition_name_Data(Tenant_Partition)
go
grant select, insert, update, delete on tenant_Import to a_named_role
go
alter table tenant_Import
add constraint pk_Import_Data
primary key (Tenant_Partition, Tenant_Id, Import_Data_Id)
on partition_name_Data(Tenant_Partition)
go
create index ix1_Import_Data
on tenant_Import (Tenant_Partition, Tenant_Id, Map_Id)
with fillfactor = 75
on partition_name_Index(Tenant_Partition)
go
我在这个表中添加了行。
如果我尝试更改一个值(例如将 null 更改为非 null)并单击 SSMS 中的保存,则会出现错误:
“tenant_Import”表 - 无法修改表。关键字“DEFAULT”附近的语法不正确。
关于可能导致这种情况的任何想法?这是在 SQL Server 2005 Enterprise 中。
==================================================== ============================ 一些评论/答案要求的更改脚本如下(我将 DateInserted 从 not null 更改为 null ,但如果我尝试更改任何列,则会出现错误消息):
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.tenant_Import
DROP CONSTRAINT DF__tenant_Im__Audit__740F363E
GO
ALTER TABLE dbo.tenant_Import
DROP CONSTRAINT DF__tenant_Im__DateI__75035A77
GO
CREATE TABLE dbo.Tmp_tenant_Import
(
Import_Data_Id bigint NOT NULL IDENTITY (101000000000000, 1),
Audit_Login_Id bigint NOT NULL,
Tenant_Id bigint NOT NULL,
Tenant_Partition bigint NOT NULL,
Map_Id bigint NOT NULL,
Filename nvarchar(500) NOT NULL,
DataFile varbinary(MAX) NOT NULL,
Status int NOT NULL,
DateInserted datetime NULL,
DateProcessed datetime NULL
) ON partition_name_Data(Tenant_Partition)
TEXTIMAGE_ON DEFAULT
GO
GRANT DELETE ON dbo.Tmp_tenant_Import TO a_named_role AS dbo
GO
GRANT INSERT ON dbo.Tmp_tenant_Import TO a_named_role AS dbo
GO
GRANT SELECT ON dbo.Tmp_tenant_Import TO a_named_role AS dbo
GO
GRANT UPDATE ON dbo.Tmp_tenant_Import TO a_named_role AS dbo
GO
ALTER TABLE dbo.Tmp_tenant_Import ADD CONSTRAINT
DF__tenant_Im__Audit__740F363E DEFAULT ((0)) FOR Audit_Login_Id
GO
ALTER TABLE dbo.Tmp_tenant_Import ADD CONSTRAINT
DF__tenant_Im__DateI__75035A77 DEFAULT (getdate()) FOR DateInserted
GO
SET IDENTITY_INSERT dbo.Tmp_tenant_Import ON
GO
IF EXISTS(SELECT * FROM dbo.tenant_Import)
EXEC('INSERT INTO dbo.Tmp_tenant_Import (Import_Data_Id, Audit_Login_Id, Tenant_Id, Tenant_Partition, Map_Id, Filename, DataFile, Status, DateInserted, DateProcessed)
SELECT Import_Data_Id, Audit_Login_Id, Tenant_Id, Tenant_Partition, Map_Id, Filename, DataFile, Status, DateInserted, DateProcessed FROM dbo.tenant_Import WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_tenant_Import OFF
GO
DROP TABLE dbo.tenant_Import
GO
EXECUTE sp_rename N'dbo.Tmp_tenant_Import', N'tenant_Import', 'OBJECT'
GO
ALTER TABLE dbo.tenant_Import ADD CONSTRAINT
pk_Import_Data PRIMARY KEY CLUSTERED
(
Tenant_Partition,
Tenant_Id,
Import_Data_Id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON partition_name_Data(Tenant_Partition)
GO
CREATE NONCLUSTERED INDEX ix1_Import_Data ON dbo.tenant_Import
(
Tenant_Partition,
Tenant_Id,
Map_Id
) WITH( PAD_INDEX = OFF, FILLFACTOR = 75, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON partition_name_Index(Tenant_Partition)
GO
COMMIT