3

Tengo el siguiente Script.

USE [PS_GameData]
GO

/****** Object:  Table [dbo].[Guilds]    Script Date: 07/24/2018 17:33:22 ******/
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

Lo quiero Ejecutar pero al intertar Crear la tabla me da error:

Msg 2714, Level 16, State 5, Line 2
There is already an object named 'PK_Guilds' in the database.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 4902, Level 16, State 1, Line 2
Cannot find the object "dbo.Guilds" because it does not exist or you do not `have permissions.`

Creo debo borar el PK_Guilds pero no se donde o como la consigo en la DB de SQL server 2008 R2

1 respuesta 1

3

Si no sabes en que Tabla esta el constraint, puedes correr esta query:

USE databasename; 

GO

SELECT i.name AS IndexName, OBJECT_NAME(ic.OBJECT_ID) AS TableName, 
       COL_NAME(ic.OBJECT_ID,ic.column_id) AS ColumnName
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic
ON i.OBJECT_ID = ic.OBJECT_ID
AND i.index_id = ic.index_id
WHERE i.is_primary_key = 1

Luego para borrarla:

ALTER TABLE "table_name"
DROP CONSTRAINT "CONSTRAINT_NAME";

O si es mas facil, simplemente cambiale el nombre al constraint.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.