[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

After i add primary key, it doesn't show up in Design mode of the table

Hi, I'm using sql 2005.  I use the script below to add the primary key and it executed successfully.  However, the primary key doesn't show up in the design mode.  I can see the PK in the tree on the left under Columns and the Keys folder.  
I have to manually do it in design again for this to show up.  What's wrong here and how can I fix this script.  I need to create this script for several tables that needs this done  and repeat this a couple more times.
Another question, since I can ssis to work (sql 2005 and vs2008 don't work together), I'm just creating TSql SP to clean up and transform a imported database.  I'm just curious, does SSIS really would save much more work from scripting if I were to use that instead of coding the TSQL sp?
Thank you.
Here is my script,
alter table dbo.q_history_type add HistoryTypeId int identity(1,1) not null
constraint [PK_dbo.q_history_type_HistoryTypeId] primary key clustered (HistoryTypeId asc)
WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
0
lapucca
Asked:
lapucca
  • 2
  • 2
2 Solutions
 
8080_DiverCommented:
Did you, by any chance, happen to have opened the table in Design mode before you executed the script in another query window?  If so, the query window with the table design init is a static copy of the design of the table before you modified it with the script.  In other words, when it was opened, there was no such Primary Key, so it has no idea one now exists.

You can also use the sp_foreachtable (system) stored procedure with a script that only adds the identity column if a PK doesn't exist on the table.  
0
 
Ryan McCauleyCommented:
I just ran this script against a SQL 2005 test server I have and they key now shows up in design view with no issues, so your script is correct.

Do you see your key in this list of you run the second script in this link?

http://blogs.msdn.com/b/sqltips/archive/2005/09/16/469136.aspx

If so, then it's set up correctly. Try closing and re-opening your design view of the table, as it only refreshes the view when that screen loads. Opening the design view after your script has finished running should show the key - if it doesn't, can you post the version (full number, like 9.0.4053) of both your SQL Server and your SSMS?
0
 
lapuccaAuthor Commented:
No, the table is not opened in any way when I executed the script.  However, I have database diagram that's opened at the time.  Would that affect it?  Thanks.

Ray, I don't know what you mean by "Do you see your key in this list of you run the second script in this link?"  I tried refresh the whole database and it still doesn't show up.  Thanks.
0
 
8080_DiverCommented:
lapucca,

Did you refresh the database with the Diagram still open?
If you try to create the PK again (without having the Diagram open), does the database engine object and tell you it already exists?

Did you run either of the scripts in the link taht Ray provided?  If not, try doing so and then let us know if the index shows up; if you did run one of the scripts, did the PK show up?
0
 
lapuccaAuthor Commented:
I think it;s cause by open diagram.  thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now