0

这是我现在的桌子。

USE [PS_GameData]
GO

/****** Object:  Table [dbo].[Guilds]    Script Date: 04/04/2012 11:58:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Guilds](
    [RowID] [int] IDENTITY(1,1) NOT NULL,
    [GuildID] [int] NOT NULL,
    [GuildName] [varchar](30) NOT NULL,
    [MasterUserID] [varchar](12) NOT NULL,
    [MasterCharID] [int] NOT NULL,
    [MasterName] [varchar](30) NOT NULL,
    [Country] [tinyint] NOT NULL,
    [TotalCount] [smallint] NOT NULL,
    [GuildPoint] [int] NOT NULL,
    [Del] [tinyint] NOT NULL,
    [CreateDate] [datetime] NOT NULL,
    [DeleteDate] [datetime] NULL,
 CONSTRAINT [PK_Guilds] PRIMARY KEY CLUSTERED 
(
    [GuildID] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =   ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Guilds] ADD  CONSTRAINT [DF_Guilds_Del]  DEFAULT ((0)) FOR [Del]
GO

我正在尝试将其更改为此。

USE [PS_GameData]
GO
/****** Object: Table [dbo].[Guilds] Script Date: 09/29/2011 06:36:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Guilds](
    [RowID] [int] IDENTITY(1,1) NOT NULL,
    [GuildID] [int] NOT NULL,
    [GuildName] [varchar](30) COLLATE Chinese_PRC_Stroke_CI_AI NOT NULL,
    [MasterUserID] [varchar](12) COLLATE Chinese_PRC_Stroke_CI_AI NOT NULL,
    [MasterCharID] [int] NOT NULL,
    [MasterName] [varchar](30) COLLATE Chinese_PRC_Stroke_CI_AI NOT NULL,
    [Country] [tinyint] NOT NULL,
    [TotalCount] [smallint] NOT NULL,
    [GuildPoint] [int] NOT NULL,
    [Del] [tinyint] NOT NULL CONSTRAINT [DF_Guilds_Del] DEFAULT (0),
    [CreateDate] [datetime] NOT NULL,
    [DeleteDate] [datetime] NULL,
CONSTRAINT [PK_Guilds] PRIMARY KEY CLUSTERED 
(
    [GuildID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF  

这是我的错误:

Msg 2714, Level 16, State 6, Line 2
There is already an object named 'Guilds' in the database.
Msg 1781, Level 16, State 1, Line 2
Column already has a DEFAULT bound to it.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.

我已经删除了表 Guilds 并尝试创建另一个名为 guilds 的表并插入脚本,但脚本保持不变或者它说 Guilds 已经在数据库中。

4

1 回答 1

0

尝试在新 DDL 的开头显式删除表:

USE [PS_GameData]
GO
if exists(
    select 1
    from sys.objects o
    inner join sys.schemas s on s.schema_id=o.schema_id
    where o.[type]='U'
    and s.name='dbo'
    and o.name='Guilds'
)
drop table [dbo].[Guilds];
go

/****** Object: Table [dbo].[Guilds] Script Date: 09/29/2011 06:36:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Guilds](
    [RowID] [int] IDENTITY(1,1) NOT NULL,
    [GuildID] [int] NOT NULL,
    [GuildName] [varchar](30) COLLATE Chinese_PRC_Stroke_CI_AI NOT NULL,
    [MasterUserID] [varchar](12) COLLATE Chinese_PRC_Stroke_CI_AI NOT NULL,
    [MasterCharID] [int] NOT NULL,
    [MasterName] [varchar](30) COLLATE Chinese_PRC_Stroke_CI_AI NOT NULL,
    [Country] [tinyint] NOT NULL,
    [TotalCount] [smallint] NOT NULL,
    [GuildPoint] [int] NOT NULL,
    [Del] [tinyint] NOT NULL CONSTRAINT [DF_Guilds_Del] DEFAULT (0),
    [CreateDate] [datetime] NOT NULL,
    [DeleteDate] [datetime] NULL,
CONSTRAINT [PK_Guilds] PRIMARY KEY CLUSTERED 
(
    [GuildID] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
于 2012-04-05T01:11:18.457 回答