?
Solved

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

Posted on 2011-03-11
5
Medium Priority
?
321 Views
Last Modified: 2012-05-11
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
Comment
Question by:lapucca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
8080_Diver earned 1000 total points
ID: 35117683
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
 
LVL 28

Assisted Solution

by:Ryan McCauley
Ryan McCauley earned 1000 total points
ID: 35128582
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
 

Author Comment

by:lapucca
ID: 35131060
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
 
LVL 22

Expert Comment

by:8080_Diver
ID: 35131423
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
 

Author Closing Comment

by:lapucca
ID: 35143479
I think it;s cause by open diagram.  thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question