Question

how do i update primary key

Asked by: SirReadAlot

Experts,

I have been on this for days.  The primary key in my database is used as a product id, so it is not set to autoincrement.

I CAN UPDATE other fields but not the prodid,
how do i correct this

thanks

========================sp=========================
ALTER       PROCEDURE SPR_UPDATE_PRODUCTS
      (
       @prodID         int,
       @prodCode       varchar(10),
      @prodName       varchar(30),
      @prodDesc       varchar(200),
      @pfID           int,
      @prodLicName    varchar(50),
      @prodLicEncKey  varchar(20),
      @supported      smallint,
      @licVersion     smallint,
      @prodAltCode    varchar(10)
     )
AS
UPDATE product SET
   
      prodID       =@prodID,
      prodCode     =@prodCode,
      prodName     =@prodName,      
      prodDesc     =@prodDesc,      
      pfID         =@pfID,          
      prodLicName   =@prodLicName,    
      prodLicEncKey =@prodLicEncKey,
      supported     =@supported,    
      licVersion    =@licVersion,    
      prodAltCode   =@prodAltCode  
WHERE
       prodID = @prodID
GO


==============================calling code==================================
 'Updates users
    Public Shared Function UpdateProduct(ByVal productProfile As ProductProfile) As Boolean
        Dim DBConnection As SqlConnection = Connection()
        Dim ProdID As SqlParameter
        DBConnection.Open()
        Try
            Dim cmdproduct As SqlCommand = New SqlCommand("SPR_UPDATE_PRODUCTS", DBConnection)
            cmdproduct.CommandType = CommandType.StoredProcedure
            cmdproduct.Parameters.Add("@prodID", productProfile.prodID)
            cmdproduct.Parameters.Add("@prodCode", productProfile.prodCode)
            cmdproduct.Parameters.Add("@prodName", productProfile.prodName)
            cmdproduct.Parameters.Add("@prodDesc", productProfile.prodDesc)
            cmdproduct.Parameters.Add("@pfID", productProfile.pfID)
            cmdproduct.Parameters.Add("@prodLicName", productProfile.prodLicName)
            cmdproduct.Parameters.Add("@prodLicEncKey", productProfile.prodLicEncKey)
            cmdproduct.Parameters.Add("@supported", productProfile.supported)
            cmdproduct.Parameters.Add("@licVersion", productProfile.licVersion)
            cmdproduct.Parameters.Add("@prodAltCode", productProfile.prodAltCode)
                    Dim iCount As Integer
            iCount = cmdproduct.ExecuteNonQuery()
            If iCount > 0 Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex.ToString)
        Finally
            DBConnection.Close()
        End Try
    End Function

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-04-13 at 01:50:02ID22509195
Tags

primary

,

key

,

update

Topic

MS SQL Server

Participating Experts
7
Points
500
Comments
29

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. .net 2.0 sqlconnection sharing
    Hey Experts, I'm converting some winforms vb.net 2.0 code over from the oledb connections to the sqlconnections (I moved some data from access to sql server) in my ole based code, I had no trouble opening 3 or 4 datareaders off one connection I converted my code f...
  2. VARCHARs for primary keys.
    Dear experts, What would be the impact of VARCHAR fields as primary keys? Please advice! many thanks
  3. passing querystring of a primary key
    Hello, on page 1, I am created a new "recipe". On page 2 I am picking up that recipe through a querystring. I need to have a uniquely identify id for that recipe, so I have a primary key column in SQL. The problem is, page 1 creates the recipe, and page 2 picks u...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ved17novPosted on 2007-04-13 at 01:58:52ID: 18904150

SET IDENTITY_INSERT tablename ON

and then you can use explicitly insert the data.

 

by: SirReadAlotPosted on 2007-04-13 at 02:04:01ID: 18904171

hi, i got this error

Table 'product' does not have the identity property. Cannot perform SET operation.

=======================================================
CREATE TABLE [dbo].[product] (
      [prodID] [int] NOT NULL ,
      [prodCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [prodName] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
      [prodDesc] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [pfID] [int] NULL ,
      [prodLicName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
      [prodLicEncKey] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
      [supported] [smallint] NULL ,
      [licVersion] [smallint] NULL ,
      [prodAltCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO

 

by: SirReadAlotPosted on 2007-04-13 at 02:05:18ID: 18904181

an not to sure about this,

i am trying to update

SET IDENTITY_INSERT tablename ON

and then you can use explicitly insert the data.

 

by: aneeshattingalPosted on 2007-04-13 at 02:07:39ID: 18904188

you are trying to update the ProdID with the current value, so no change for ProdID valeue

UPDATE product SET
       prodID       =@prodID, ------------------------------------------ check here
      prodCode     =@prodCode,
       prodAltCode   =@prodAltCode  
WHERE        prodID = @prodID  ------------------------------------- and here
GO

 

by: ved17novPosted on 2007-04-13 at 02:10:40ID: 18904198

Hi you can't update the Identity Column.
as you code prodID is not a Identity column.

tell me prodID  have primary key??

if yes, you can't update the same prodID which is already in the table and you can use any other id which is not exists in the table and can update with that.

post your error which you are geeting.

 

by: ram2098Posted on 2007-04-13 at 02:12:23ID: 18904203

Please check the relations for the product table...

if you have referenced tables and the specific data you are trying to modify is present in child tables, you will not be able to update. You may have to delete those child rows before update the master.

 

by: ved17novPosted on 2007-04-13 at 02:12:51ID: 18904206

why you are trying to updated that column which is used for filter the record and you are also updating with the same value.

Please look below modified code...


ALTER       PROCEDURE SPR_UPDATE_PRODUCTS
      (
       @prodID         int,
       @prodCode       varchar(10),
      @prodName       varchar(30),
      @prodDesc       varchar(200),
      @pfID           int,
      @prodLicName    varchar(50),
      @prodLicEncKey  varchar(20),
      @supported      smallint,
      @licVersion     smallint,
      @prodAltCode    varchar(10)
     )
AS
UPDATE product SET
      prodCode     =@prodCode,
      prodName     =@prodName,      
      prodDesc     =@prodDesc,      
      pfID         =@pfID,          
      prodLicName   =@prodLicName,    
      prodLicEncKey =@prodLicEncKey,
      supported     =@supported,    
      licVersion    =@licVersion,    
      prodAltCode   =@prodAltCode  
WHERE
       prodID = @prodID
GO

 

by: RacimoPosted on 2007-04-13 at 03:09:41ID: 18904370

I suggest you establish the CASCADE UPDATE and relationships then change the data type. to autoincrement with a reseed.  Never tried it but it should work...

 

by: SirReadAlotPosted on 2007-04-13 at 03:46:38ID: 18904486

guys

The primary key in my database is used as a product id, so it is not set to autoincrement.

the values of prodid could be 10, 20, 45 but they are 1,2,3 as normal

so ved17nov, i know i can't update that primary key and i am not geting any errors even with breakpoiont on.

how do i fix it,

else how do i use this cascade update

thanks

 

by: SirReadAlotPosted on 2007-04-13 at 03:47:31ID: 18904493

how do i do this?
I suggest you establish the CASCADE UPDATE and relationships then change the data type. to autoincrement with a reseed.  Never tried it but it should work...

 

by: LowfatspreadPosted on 2007-04-13 at 05:52:05ID: 18904949

>i know i can't update that primary key and i am not geting any errors even with breakpoiont on.

nothing stops you from updating a primary key in a sql server database per-se....

its BAD FORM to do so however...

i've read throuygh the question and cannot make out what your actual problem is ...

THIS HAS GOT NOTHING TO DO WITH IDENTITY as the questionner has said several times...

if you do allow the product id to change then the procedure needs an OLDProductID and A NewProductid
parameter

so update ...
       set productid=@newproductid
     where productid=@oldProductid

hth    

 

by: SirReadAlotPosted on 2007-04-13 at 06:01:11ID: 18904998

hi lowfat

do u mean somithing like this
ALTER PROCEDURE SPR_UPDATE_PRODUCTS
      (
       @prodID         int,
       @numUniqueDevices int,
       @matchBaseLicOnly  int,
       @prodCode       varchar(10),
       @prodName       varchar(30),
       @prodDesc       varchar(200),
       @pfID           int,
       @prodLicName    varchar(50),
       @prodLicEncKey  varchar(20),
       @supported      smallint,
       @licVersion     smallint,
       @prodAltCode    varchar(10)
     )
AS
UPDATE product SET
   
      prodID       =@prodID,
      prodCode     =@prodCode,
      prodName     =@prodName,      
      prodDesc     =@prodDesc,      
      pfID         =@pfID,          
      prodLicName   =@prodLicName,    
      prodLicEncKey =@prodLicEncKey,
      supported     =@supported,    
      licVersion    =@licVersion,    
      prodAltCode   =@prodAltCode,
set prodid=@newprodid
WHERE
      productid=@oldProductid

 

by: SirReadAlotPosted on 2007-04-13 at 06:07:33ID: 18905032

i've read throuygh the question and cannot make out what your actual problem is ...>>


whilst i can update other fields in the table, i cannot update the prodid

thanks

 

by: SirReadAlotPosted on 2007-04-13 at 06:13:51ID: 18905068

ok

ALTER PROCEDURE SPR_UPDATE_PRODUCTS
      (
       @prodID         int,
       @numUniqueDevices int,
       @matchBaseLicOnly  int,
       @prodCode       varchar(10),
       @prodName       varchar(30),
       @prodDesc       varchar(200),
       @pfID           int,
       @prodLicName    varchar(50),
       @prodLicEncKey  varchar(20),
       @supported      smallint,
       @licVersion     smallint,
       @prodAltCode    varchar(10),
       @newprodid      int,
       @oldprodid      int
     )
AS
UPDATE product SET
   
      prodID       =@prodID,
      prodCode     =@prodCode,
      prodName     =@prodName,      
      prodDesc     =@prodDesc,      
      pfID         =@pfID,          
      prodLicName   =@prodLicName,    
      prodLicEncKey =@prodLicEncKey,
      supported     =@supported,    
      licVersion    =@licVersion,    
      prodAltCode   =@prodAltCode,
       prodID=@newprodID
WHERE
      prodID=@oldProdID

i will test this

 

by: SirReadAlotPosted on 2007-04-13 at 06:36:36ID: 18905222

i now have this,


   'Updates users
    Public Shared Function UpdateProduct(ByVal productProfile As ProductProfile) As Boolean
        Dim DBConnection As SqlConnection = Connection()
        Dim ProdID As SqlParameter
        DBConnection.Open()
        Try
            Dim cmdproduct As SqlCommand = New SqlCommand("SPR_UPDATE_PRODUCTS", DBConnection)
            cmdproduct.CommandType = CommandType.StoredProcedure
            cmdproduct.Parameters.Add("@prodID", productProfile.prodID)
            cmdproduct.Parameters.Add("@newprodID", productProfile.newprodID)
            cmdproduct.Parameters.Add("@prodCode", productProfile.prodCode)
            cmdproduct.Parameters.Add("@prodName", productProfile.prodName)
            cmdproduct.Parameters.Add("@prodDesc", productProfile.prodDesc)
            cmdproduct.Parameters.Add("@pfID", productProfile.pfID)
            cmdproduct.Parameters.Add("@prodLicName", productProfile.prodLicName)
            cmdproduct.Parameters.Add("@prodLicEncKey", productProfile.prodLicEncKey)
            cmdproduct.Parameters.Add("@supported", productProfile.supported)
            cmdproduct.Parameters.Add("@licVersion", productProfile.licVersion)
            cmdproduct.Parameters.Add("@prodAltCode", productProfile.prodAltCode)
            'updates data in the licPolicy table
            cmdproduct.Parameters.Add("@numUniqueDevices", productProfile.numUniqueDevices)
            cmdproduct.Parameters.Add("@matchBaseLicOnly", productProfile.matchBaseLicOnly)

            Dim iCount As Integer
            iCount = cmdproduct.ExecuteNonQuery()
            If iCount > 0 Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex.ToString)
        Finally
            DBConnection.Close()
        End Try
    End Function
 ============================and
ALTER PROCEDURE SPR_UPDATE_PRODUCTS
      (
       @prodID            int,
       @numUniqueDevices  int,
       @matchBaseLicOnly  int,
       @prodCode          varchar(10),
       @prodName          varchar(30),
       @prodDesc          varchar(200),
       @pfID              int,
       @prodLicName       varchar(50),
       @prodLicEncKey     varchar(20),
       @supported         smallint,
       @licVersion        smallint,
       @prodAltCode      varchar(10),
       @newprodID        int,
       @oldprodID        int
     )
AS
UPDATE product SET
   
      prodID       =@prodID,
      prodCode     =@prodCode,
      prodName     =@prodName,      
      prodDesc     =@prodDesc,      
      pfID         =@pfID,          
      prodLicName   =@prodLicName,    
      prodLicEncKey =@prodLicEncKey,
      supported     =@supported,    
      licVersion    =@licVersion,    
      prodAltCode   =@prodAltCode,
      prodID=@newprodID
WHERE
      prodID=@oldProdID

on breakpoint
cmdproduct.Parameters.Add("@newprodID", productProfile.newprodID) value is
"nothing" instead of 111, for instance.

 

by: LowfatspreadPosted on 2007-04-13 at 10:31:56ID: 18907208

UPDATE product SET
   
 --     prodID       =@prodID,
      prodCode     =@prodCode,
      prodName     =@prodName,      
      prodDesc     =@prodDesc,      
      pfID         =@pfID,          
      prodLicName   =@prodLicName,    
      prodLicEncKey =@prodLicEncKey,
      supported     =@supported,    
      licVersion    =@licVersion,    
      prodAltCode   =@prodAltCode,
      prodID=@newprodID
WHERE
      prodID=@oldProdID



but you have to initialise the oldprodid and newprodid parameters correctly in your code as well.....


 

by: ScottPletcherPosted on 2007-04-13 at 13:14:28ID: 18908249

By definition, you *cannot* update the primary key in SQL Server.  SQL will simply not allow it.

 

by: RacimoPosted on 2007-04-14 at 01:49:02ID: 18910203


<<By definition, you *cannot* update the primary key in SQL Server.  SQL will simply not allow it.>>
 I would add to that a primary key that requires *frequent* updating certainly is *not* a primary key (speaking of the fundamental definition of primary key).

 

by: ScottPletcherPosted on 2007-04-16 at 07:51:09ID: 18918048

Theory is good, but real life must take priority, so I think SQL should allow a "primary key" to be changed, even if MS wanted to require a special role/permission to do it.

 

by: RacimoPosted on 2007-04-16 at 08:38:14ID: 18918455

<<Theory is good, but real life must take priority, so I think SQL should allow a "primary key" to be changed, even if MS wanted to require a special role/permission to do it>>

I respectfully disagree on the perspective (always a pleasure Scott !!! ;)).  I do not believe there should any priority of any kind: both are equally important.  Poor implementation with good theory supporting is bad.  implementation with no theory at all is even worse: the chances for building a sound db schema without *some* undistorted knowledge of fundamentals is close to zero.    A true primary key should be *stable* in *any* case else chances it is everything but a primary key.  If a primary key is updated and changed too frequently, it simply means that the designer did not do a good job into selecting it among candidate keys.  Or it may mean that the system was not built seriously.  

I am convinced that's it's because too many practitioners choose to ignore fundamental design rules in RM that they create real life problems on hard to maintain systems (NULLS, redundancy, dupplicates, etc...).  After that, too many practitionners keep running behind problems they created themselves.  

At *best*, choosing to ignore fundamentals RM will make you an average practitioners but as DATE stated...*Intellectual agility and experience may replace fundamental knowledge in a limited manner*...

At *worst*, it pours in tons of XML (hierarchical) in db's and brings us back 40 years in the past (old IMS,MVS systems) when people had to write entire programs to do one single update...

Theory is not here to make people life harder and imposes in no way to make mutually exclusive choices between real life and theory.  It is perfectly valid and possible to design better systems by a better study of data fundamentals even on good ol' SQL Systems.  I think it is the duty and role of all experts in this board to help people not only with hacks and daily tricks but also by encouraging them into finding out more about the fundamentals of database management.   I unfortunately do not believe we have as db professionals the luxury of choosing between theory and implementation (or real life)..

Guess that was my rant against ignorance of data fundamentals....(or was it that stupid developper who brought down an entire db down this afternoon in one single select because of unormalized schema)...

 

by: SirReadAlotPosted on 2007-04-16 at 08:39:54ID: 18918467

thanks you all.

i shall close down this ques

 

by: RacimoPosted on 2007-04-16 at 08:48:07ID: 18918536

<<i shall close down this ques>>
You are welcome.  Hope the various comments helped...

 

by: SirReadAlotPosted on 2007-04-16 at 08:59:15ID: 18918618

yes they did.

thanks all

 

by: appariPosted on 2007-04-16 at 22:19:42ID: 18922406

Scott:
>>By definition, you *cannot* update the primary key in SQL Server.  SQL will simply not allow it.

i think nowhere this is defined. i just tested and sqlserver does allow changing PKey value. can you provide pointers from where did you get  this.
yes i agree that its a bad practice to change primary key values.

 

by: appariPosted on 2007-04-16 at 22:21:37ID: 18922413

and this is the explanation of Primary key from BOL

A table typically has a column or combination of columns that contain values that uniquely identify each row in the table. This column, or columns, is called the primary key (PK) of the table and enforces the entity integrity of the table. You can create a primary key by defining a PRIMARY KEY constraint when you create or modify a table.

A table can have only one PRIMARY KEY constraint, and a column that participates in the PRIMARY KEY constraint cannot accept null values. Because PRIMARY KEY constraints guarantee unique data, they are frequently defined on an identity column.

When you specify a PRIMARY KEY constraint for a table, the SQL Server 2005 Database Engine enforces data uniqueness by creating a unique index for the primary key columns. This index also permits fast access to data when the primary key is used in queries. Therefore, the primary keys that are chosen must follow the rules for creating unique indexes.

If a PRIMARY KEY constraint is defined on more than one column, values may be duplicated within one column, but each combination of values from all the columns in the PRIMARY KEY constraint definition must be unique.

As shown in the following illustration, the ProductID and VendorID columns in the Purchasing.ProductVendor table form a composite PRIMARY KEY constraint for this table. This makes sure that that the combination of ProductID and VendorID is unique.


When you work with joins, PRIMARY KEY constraints relate one table to another. For example, to determine which vendors supply which products, you can use a three-way join between the Purchasing.Vendor table, the Production.Product table, and the Purchasing.ProductVendor table. Because ProductVendor contains both the ProductID and VendorID columns, both the Product table and the Vendor table can be accessed by their relationship to ProductVendor.

 

by: LowfatspreadPosted on 2007-04-17 at 00:06:19ID: 18922655

Scott
I agree with your sentiments

but SQL Server does allow you to change Primary Key values ,,,

but changing a primary key value is always symptomatic of some underlying design problem...

(just think of the havoc is causes for any triggers on the table...
  there is nothing which tells you which before (deleted)  matches  which after (inserted)  

 

by: RacimoPosted on 2007-04-17 at 01:01:25ID: 18922784

<<but changing a primary key value is always symptomatic of some underlying design problem...>>
Agreed.  A primary key is a concept that is independent from a specific technology implementation.

It is safe to say that a primary key that requires frequent updating is no primary key at all.  

Regards...

 

by: ScottPletcherPosted on 2007-04-18 at 11:35:21ID: 18933961

Hmm, interesting.  Sorry about the false info.  I know I had trouble with this in the past.

 

by: RacimoPosted on 2007-04-18 at 12:41:47ID: 18934498

<<I know I had trouble with this in the past.>>
I did too until I realized that most SQL Server product designers had no clue about what a primary key is.  When looking and studying more deeply the concept of primary keys (according to their fundamental definitions) and see how they are actually implemented on SQL Server, it is easy t get confused:

>  First, most product designers do not understand that a pk is logical concept that may be implemented *physically* in several ways.  As a consequence, a strong confusion often arises between primary keys and indexes.
> Second, most direct image systems do not have sufficient support for primary keys:
           --> pk implementation are optional when they should be mandatory (careful I am not talking about indexes)
           --> surrogate key implementations are poor: a simple counter does not constitute a surrogate key as long as additional constraints are implemented on the natural primary keys implementations
           --> SQL Server and maybe its competitors poorly supports composite primary keys/foreign keys referential integrity...One has to program a function a with a check (or a trigger) to make sure a unique combination (composite key) exists in another table.  As result people have a bias to use a surrogate key when nothing forces its use.
> Third,some of the most important characteristic of a primary key is to be *unique* (mandatory), *stable* (strongly advised). *familiar (preferable)*.   On most systems I find on my daily workno unicity

So if you ask me, I require the help of MS mainly when it comes to double check syntax on BOL but when it comes to design I prefer to simply ignore most of their fallacies....

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...