473,464 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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?
Apr 22 '10 #1
1 2967
SQLpro
1
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_SCHEMA.TABLE_CONSTRAINTS
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 * * * * *
Apr 27 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: lostinpython | last post by:
I'm having trouble writing a program that figures out a prime number. Does anyone have an idea on how to write it? All I know is that n > 2 is prim if no number between 2 and sqrt of n...
0
by: ak | last post by:
Hi! I have a dynaset from a select string and want to insert a bunch of values into the columns/fields. Some of the columns are of type number afaik e.g. number(3) meaning only 3 digits are...
4
by: Dmitri | last post by:
I just looked at a coworker's stored procedure and this person is dropping 4 Foreign key constraints and then re-adding them after processing the required logic (updating rows in the 4 tables in...
3
by: venu | last post by:
Hi, I have a different requirement and it is : I need to validate a phone number field. It may or may not be a US phone number. The constraints are : *********************** # It should...
19
by: eric.nave | last post by:
this is a slight change to a fequently asked question around here. I have a table which contains a "sortorder" column where a user can specify some arbitrary order for records to be displayed in. ...
10
by: teddysnips | last post by:
SQL Server 2000 (DDL below) If I try to run this code in QA: SET IDENTITY_INSERT tblAdminUsers ON INSERT INTO tblAdminUsers (fldUserID, fldUsername, fldPassword, fldFullname,
11
by: Petulant | last post by:
Hello~ Help Please~ I am new to Access, so am a little behind the learning curve. I have a query that I have been running for a while that has worked fine and now (with no changes) is throwing up...
7
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
73
by: cesco | last post by:
I have to generate a list of N random numbers (integer) whose sum is equal to M. If, for example, I have to generate 5 random numbers whose sum is 50 a possible solution could be . Is there a...
3
by: Dameon99 | last post by:
Hi.. Im experiencing a weird error I dont know how to fix. I have a scanner object and whenever I use nextInt, anything above 3 causes the program to crash saying and links me to this line of the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.