PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > Update query after switching PK from varchar to int(Identity)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Update query after switching PK from varchar to int(Identity)

Réponse
 
LinkBack Outils de la discussion
Vieux 03/09/2008, 21h56   #1
AkAlan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Update query after switching PK from varchar to int(Identity)

I have two tables that are related. The first table (Sites) has a varchar(4)
for a primary key and I want to change it to be an int identity column. I
broke the relationships and renamed the current pk column to siteID_Old. Then
created a new column called siteID and made it int identity. Now I need to
update the other table (Location) which has an fk for siteID and change the
values so they correspond to the new values I just created in the Sites table.
I'm not really sure how to proceed.
Do I rename the siteID column in the Locations table to siteId_Old and
create a new column called siteID and then perform an update?

I tried creating a stored procedure from an MS Access project but it only
allows one table in the window when I changed it to an Update Query so I
don't know how to reference the Sites table to perform the update. I am
taking a stab at the TSql statement but not sure exactly how it should be
written. I am using a copy of the database in case I really screw it up. Any
Ideas?
Thanks.


  Réponse avec citation
Vieux 03/09/2008, 23h35   #2
Eric Isaacs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Update query after switching PK from varchar to int(Identity)

Rename the old foreign key in the other table to siteid_old as well,
add a new siteid field that's an INT field.

Then run SQL similar to the following...

UPDATE
L
SET
L.SiteID= s.SiteID
FROM
Location L
INNER JOIN Sites s ON L.SiteID_old = s.SiteID_old

-Eric Isaacs


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h02.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07125 seconds with 10 queries