MONDE-HISTOIRE-CULTURE GÉNÉRALE
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
MONDE-HISTOIRE-CULTURE GÉNÉRALE

Vues Du Monde : ce Forum MONDE-HISTOIRE-CULTURE GÉNÉRALE est lieu d'échange, d'apprentissage et d'ouverture sur le monde.IL EXISTE MILLE MANIÈRES DE MENTIR, MAIS UNE SEULE DE DIRE LA VÉRITÉ.
 
AccueilAccueil  PortailPortail  GalerieGalerie  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  Connexion  
Derniers sujets
Marque-page social
Marque-page social reddit      

Conservez et partagez l'adresse de MONDE-HISTOIRE-CULTURE GÉNÉRALE sur votre site de social bookmarking
QUOI DE NEUF SUR NOTRE PLANETE
LA FRANCE NON RECONNAISSANTE
Ephémerides
Le deal à ne pas rater :
Cdiscount : -30€ dès 300€ d’achat sur une sélection Apple
Voir le deal

 

 SQL Basics :The Update Statement

Aller en bas 
AuteurMessage
mihou
Rang: Administrateur
mihou


Nombre de messages : 8092
Localisation : Washington D.C.
Date d'inscription : 28/05/2005

SQL Basics :The Update Statement Empty
03022006
MessageSQL Basics :The Update Statement

The Update Statement
Once we have the information in the table, we might find that there is a need to modify the data. To do so, we can use the UPDATE command. The syntax for this is

UPDATE "table_name"
SET "column_1" = [new value]
WHERE {condition}

It is easiest to use an example. Say we currently have a table as below:

Table Store_Information

store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999

We find that the sales for Los Angeles on 01/08/1999 is actually $500 instead of $300, and we need to update that particular entry. To do so, we use the following SQL:

UPDATE Store_Information
SET Sales = 500
WHERE store_name = "Los Angeles"
AND Date = "Jan-08-1999"

The resulting table would look like

Table Store_Information

store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $500 Jan-08-1999
Boston $700 Jan-08-1999

In this case, there is only one row that satisfies the condition in the WHERE clause. If there are two rows that satisfy the condition, both rows will be modified.

It is also possible to UPDATE multiple columns at the same time. The syntax in this case would look like the following:

UPDATE "table_name"
SET column_1 = [value1], column_2 = [value2]
WHERE {condition}

The UPDATE statement is used to modify the data in a table.
Syntax

UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value

Update one Column in a Row

We want to add a first name to the person with a last name of "Rasmussen":

UPDATE Person SET FirstName = 'Nina'
WHERE LastName = 'Rasmussen'

Result:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Storgt 67

Update several Columns in a Row

We want to change the address and add the name of the city:

UPDATE Person
SET Address = 'Stien 12', City = 'Stavanger'
WHERE LastName = 'Rasmussen'

Result:
LastName FirstName Address City
Nilsen Fred Kirkegt 56 Stavanger
Rasmussen Nina Stien 12 Stavanger
Revenir en haut Aller en bas
https://vuesdumonde.forumactif.com/
Partager cet article sur : reddit

SQL Basics :The Update Statement :: Commentaires

Aucun commentaire.
 

SQL Basics :The Update Statement

Revenir en haut 

Page 1 sur 1

 Sujets similaires

-
» SQL Basics :SELECT Statement
» SQL Basics :SELECT DISTINCT Statement
» SQL Basics :introduction
» SQL Basics :CREATE
» SQL Basics :TRIGGERS

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
MONDE-HISTOIRE-CULTURE GÉNÉRALE :: SCIENCES :: INFORMATIQUE-INTERNET/COMPUTER SCIENCES-
Sauter vers: