You are here: Re: How to add a PK column to a View? « MsSQL Server « IT news, forums, messages
Re: How to add a PK column to a View?

Posted by Erland Sommarskog on 11/05/07 22:40

cjeffwang@gmail.com (cjeffwang@gmail.com) writes:
> 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@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация