Solved

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

Posted on 2011-03-11
5
305 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
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
8080_Diver earned 250 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 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Error 9 48
Analysis of table use 7 42
Access Date Query 28 44
MS Sql query to list a table and join another table though all rows are not there 13 44
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now