Solved

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

Posted on 2011-03-11
5
314 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 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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