Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Creation of PK in a new DB

Author  Topic 

DAVIDS
Starting Member

2 Posts

Posted - 2015-04-14 : 07:16:13
Hi all
I have a small question about PK creation on a DB. In details I have a source db and from it I got a script to generate another db. Executing this script to create a new db I saw that the PK created are different in the last part, for example the PK in the original DB is PK__aspnet_Profile__1CF15040 while in the new DB is PK__aspnet_P__CD67DC5902DA2B35. Could create some error on SQL query or application side?

Thanks in advance

DS


DS

Kristen
Test

22859 Posts

Posted - 2015-04-14 : 07:19:47
Presumably your script which created the Primary Key (both the original and the new one) did not explicity provide a name for the key, so SQL generated a name for it.

The name is not usually used for anything, so it can be called anything you (or SQL!!) like.

However, if in the future you want to create a script that will DROP the PKey and create a new, different, one AND you want to run that script on SEVERAL databases, then it is a lot easier if every database has the same name for the PKey object.

We explicitly name every constraint, object, etc. specifically so that any UPDATE script we write can be used on DEV database then TEST database and finally PRODUCTION database.
Go to Top of Page

DAVIDS
Starting Member

2 Posts

Posted - 2015-04-14 : 07:27:32
Hi Kristen
First of all thank you for your response and thank you for your expalnation. On PROD env this could create some problem??

Regards

DS

DS
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-04-14 : 20:31:35
quote:
Originally posted by DAVIDS

On PROD env this could create some problem??



1) The name is not usually used for anything

2) If you want to create a script to modify the Object then it will help if it has a uniform name on all the databases where it is present.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2015-04-15 : 01:32:46
If you want to read more on SQL Server - ISO-11179 Naming Conventions read more on [url]http://www.sqlserver-dba.com/2011/05/iso-11179-naming-conventions-and-sql-ddl.html[/url]

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -