Weird hex number on constraints?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MisterVercetti
    New Member
    • Apr 2010
    • 1

    Weird hex number on constraints?

    When I created a few new tables, I added some foreign keys via the ALTER TABLE/ADD FOREIGN KEY command. Now I need to truncate those same tables, but in order to do so I obviously need to drop the foreign keys. But when I attempt to drop the keys, I get error message 3728: ______ is not a constraint. When I went into the table design to see what was wrong, I noticed that SQL Server is attaching strange hexadecimal numbers to the ends of my constraint names (e.g. FK_Fact_TimeID_ 10566F31), making it virtually impossible to drop them.

    Is there a way to either stop SQL Server from adding these numbers, or else find a workaround that ignores these numbers when attempting to drop the constraint?
  • SQLpro
    New Member
    • Apr 2010
    • 1

    #2
    There is two way for a workaround :
    1) add a name to all your constraints
    2) retrieve the name of the constraint in meta data tables or views

    1) add a name to the constraint :

    ALTER TABLE ... ADD CONSTRAINT MyConstraint ...
    MyConstraint will be the name of the constraint

    2) retrieving the constraint name

    SELECT CONSTRAINT_NAME
    FROM INFORMATION_SCH EMA.TABLE_CONST RAINTS
    WHERE TABLE_SCHEMA = 'MySchemaName'
    AND TABLE_NAME = 'MyTabName'
    AND CONSTRAINT_TYPE = 'ConstraitType' -- PRIMARY KEY, UNIQUE, FOREIGN KEY, CHECK

    A +

    --
    Frédéric BROUARD, Spécialiste modélisation, SGBR relationnel, optimisation, langage SQL.
    Le site sur le langage SQL et les SGBD relationnels : http://sqlpro.developpez.com/
    Expert SQL Server http://www.sqlspot.com : audit, optimisation, tuning, formation
    Le blog sur SQL / MS SQL Server http://blog.developpez.com/sqlpro
    * * * * * Enseignant au CNAM PACA et à l'ISEN à Toulon * * * * *

    Comment

    Working...