Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying a field

Status
Not open for further replies.

TiltingCode

Programmer
Apr 10, 2009
61
0
0
US
In SQL Server 2008 R2 I changed the data type of a field and when I clicked Yes to change that field a message box appeared stating:

"The following tables will be saved to your database. Do you want to continue?"

It listed the table I changed plus another table I did not touch. I chose No and confirmed this field does not exist in the other table. Why is this happening and how can I prevent the other table from appearing? For all I know that other table did not change in any way and I tried it a couple times.
 
As Frederico stated it might be part of a FK relation. And the columns don't have to have the same name.

Let's say I have a table (myTable) with the column myCol. myCol is CHAR(10), but I need to change it to VARCHAR(100). THe table has a FK with myTable2 on the column thisColumn which is CHAR(10). The name isn't the same, but the same data is kept in it. I need to change both columns at the same time. This is probably what is happening to you.

Here is a script to run on the database to find all the FKs that exist.
(I can't take credit for the code, I forget where I got it from).

Code:
SELECT f.name AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
COL_NAME(fc.parent_object_id,
fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
COL_NAME(fc.referenced_object_id,
fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id

-SQLBill


The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top