dbTalk Databases Forums  

How to add a PK column to a View?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss How to add a PK column to a View? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
cjeffwang@gmail.com
 
Posts: n/a

Default How to add a PK column to a View? - 11-05-2007 , 03:31 PM






The new table I need for an ASP project includes a PK. After creating
a View, how can I add a new PK column, which will add the increaing
integer numbers automatically? Or how do I code to
create a PK column automatically with the new View?

TIA,
Jeffrey


Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to add a PK column to a View? - 11-05-2007 , 04:40 PM






cjeffwang (AT) gmail (DOT) com (cjeffwang (AT) gmail (DOT) com) writes:
Quote:
The new table I need for an ASP project includes a PK. After creating
a View, how can I add a new PK column, which will add the increaing
integer numbers automatically? Or how do I code to
create a PK column automatically with the new View?
I'm not really sure what you and what you have not. And where the
view comes into the picture.

If you have a an existing table add need to extend the PK with a new column,
it depends on what you want to put into that column. You talk about
increasing integers automatically, but I don't really see the point
with adding such a column to an existing PK.

To add an IDENTITY column you can do

ALTER TABLE tbl ADD ident int IDENTITY

and you will be all set up. Then again, think twice if this is really
what you need. Lots of people put IDENTITY on their tables, and then
need to deal with all sorts of kludges when the IDENTITY gets in the
way.

The prime reason to use IDENTITY is that the insertion ratio is expected
to be high.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.