Help in querying hash PK and FK

All we need is an easy explanation of the problem, so here it is.

I was trying to get the name of the PK and FK. However, this is the output that I get:
PK: PK__adm_lib___3214EC067E4F7CCA
FK: FK__adm_lib_S__fk_Co__7093AB15

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

The names you found are the actual names of those keys. This happens when the UI in a tool like SSMS (SQL Server Management Studio) is used to create the keys (as opposed to manually scripting them out and choosing the names). I presume the suffix of the name is a GUID of sorts to ensure uniqueness (since two keys can’t have the same name in SQL Server).

If you want the names to be more readable when you query them, your only option is to change their names. You can use the system stored procedure sp_rename to rename your keys to a more readable name of your choosing like this: EXEC sp_rename 'SchemaName.TableName.OldKeyName', 'NewKeyName'.

This procedure can be used to rename most objects in SQL Server. Please keep in mind, if you have any other SQL scripts that were referencing the old key name, you’ll need to update them to reference the new key name.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply