![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have found very strange problem - it seems that if you create a table in the Enterprise Manager (for example, in my case the table name is MyTbl) and accept default primary key name (which in my case is PK_MyTbl and I like it), when you try to generate a script for this table, the script will omit the primary key name at all and the table will be copied to another server with absolutely different primary key name (something very cryptic like PK_MyTbl_987645.). I have about 500 tables and 1000 stored procedures and in some procedures I had to use hints with direct reference to the indexes names - how can I generate a script with PROPER index names? It also seems that the scripts for objects owned by an application role are also generated with errors - SQL Server tries to use SETUSER command, which does not work for application roles. Has anybody seen these bugs? |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Ok - here are some details: I have a table called frstx and if I open this table in the Design Mode in the Enterprise manager, I can clearly see that this table has a primary key called PK_frstx. But when I try to generate a SQL script for it (selecting option "Generate Primary keys, etc ...", I receive the following script (I left only part related to PK creation): .... ALTER TABLE [dbo].[frstx] ADD CONSTRAINT [DF__frstx__syscreate__63057124] DEFAULT (getdate()) FOR [syscreated], CONSTRAINT [DF__frstx__syscreato__63F9955D] DEFAULT (0) FOR [syscreator], CONSTRAINT [DF__frstx__sysmodifi__64EDB996] DEFAULT (getdate()) FOR [sysmodified], CONSTRAINT [DF__frstx__sysmodifi__65E1DDCF] DEFAULT (0) FOR [sysmodifier], CONSTRAINT [DF__frstx__sysguid__66D60208] DEFAULT (newid()) FOR [sysguid], PRIMARY KEY NONCLUSTERED ( [ID] ) WITH FILLFACTOR = 90 ON [PRIMARY] GO .... As you can see - there is no primary key name in the script and when I run it on another SQL Server, it generates default name for it, but since I have references to PK_frstx in the stored procedures, they just stop working. Interesting thing - if in the Design Mode I rename PK_frstx to, for example, PK_frstx_temp, save the table and rename the PK back to PK_frstx, everything starts working properly and the script now will use proper PK name: ALTER TABLE [dbo].[frstx] ADD CONSTRAINT [DF__frstx__syscreate__63057124] DEFAULT (getdate()) FOR [syscreated], CONSTRAINT [DF__frstx__syscreato__63F9955D] DEFAULT (0) FOR [syscreator], CONSTRAINT [DF__frstx__sysmodifi__64EDB996] DEFAULT (getdate()) FOR [sysmodified], CONSTRAINT [DF__frstx__sysmodifi__65E1DDCF] DEFAULT (0) FOR [sysmodifier], CONSTRAINT [DF__frstx__sysguid__66D60208] DEFAULT (newid()) FOR [sysguid], CONSTRAINT [PK_frstx] PRIMARY KEY NONCLUSTERED ( [ID] ) WITH FILLFACTOR = 90 ON [PRIMARY] GO DTS comes here because all I need to do is to export my tables and data onto different SQL Server and it does not matter what I do, the primary keys are exported with names like PK_frstx_067435078545... Why? |
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
|
I have a table, which ALREADY HAS a primary key called PK_frstx, but when I generate a SQL script for this table, I receive the following result: .. CONSTRAINT PRIMARY KEY NONCLUSTERED .. and I can NOT understand why this script has empty space instead of existing and properly named primary key. The result that I expected, was: .. CONSTRAINT [PK_frstx] PRIMARY KEY NONCLUSTERED .. So, I repeat, I have a properly named PK for the table, but SQL Server refuses to include its name into sql scripts generated for this table. |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
In my case generated script looks like: CREATE TABLE [dbo].[MyTable] ( [ColPK] [int] NOT NULL ) ON [PRIMARY] GO ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT PRIMARY KEY CLUSTERED ( [ColPK] ) ON [PRIMARY] GO I think I explained it several times - in my case there is NO primary key name in the generated sqcript (i.e. just a space between words "CONSTRAINT" and "PRIMARY"). I repeat - the table has properly named primary key, but generated script creates no-named primary key. One more interesting detail - all primary keys that have this problem have status=36 in the corresponding rows in the sysobjects table - I do not have a clue what it means. I checked several other databases on other servers and could not find any single row in sysobjects with status = 36. |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |