Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Primary Key Update

Author  Topic 

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-04-17 : 01:55:12
Hi hi,
Anyone knows how is it possible to update the primary key of the table ? There is no foreign key in the table and the primary key is not an ID as it is not meant to have duplicate records.

How do i do this :

cm = new SqlCommand("Update tbPorts set PortName= @portName, CountryName= @CountryName, City = @city, Users = @user where PortName=@portName2");

SqlParameter p1 = new SqlParameter("@portName", SqlDbType.NVarChar, 200);

SqlParameter p2 = new SqlParameter("@portName2", SqlDbType.NVarChar, 200);[/code]

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2009-04-17 : 02:13:09
Hi,
you can update the primary key in this schenario as far as it is unique and no foreign keys defined

kunal
Go to Top of Page

melon.melon
Yak Posting Veteran

76 Posts

Posted - 2009-04-17 : 03:04:09
There could be a way to update if i can store the old values before the update somewhere and pass into @portname2, how can this be done?
Go to Top of Page
   

- Advertisement -