Website Development Prices

Search Blog

Sunday, November 1, 2015

Azuriranje zapisa u bazi podataka (Updating records in the database)

Osim ucitavanja podataka iz baze, neke medju njima cete  cesto i menjati. Npr, mozete povecati cenu motora. Za to se koristi iskaz update.

Sintaksa:

update ime_tabele
set kolona1=izraz1,kolona2=izraz2,...
[where uslovi]
[order by redosled]

[limit broj]

Objasnjenje:

Poenta je da se u tabeli ime_tabele sve navedene kolone azuriraju u zavisnosti od zadatih uslova. Pomocu odredbe where azuriranje mozete ograniciti samo na odredjene redove, a pomocu odredbe limit mozete da  ogranicite ukupan broj azuriranih redova. Odredba order by koristi se samo u kombinacji sa odredbom limit; npr. kada zelite da azurirate samo prvih deset redova, a zelite prvo da ih poredjate odredjenim redosledom. Opcije low priority i ignore deluju na isti nacin kao iskazu insert


Ako zelite da povecate cene svih motora za 10%, mozete uppotrebiti iskaz update bez odredbe where.

 Primer:

update motori

set cena=cena*1.1;

Ovaj fajl sacuvajte kao azuriranje-zapisa.sql.

1. Pokrenite XAMPP. Kliknite na Admin u liniji MySQL-a ili ukucajte u address bar http://localhost/phpmyadmin/

2. Sa leve strane izaberite bazu podataka volimmotore, a sa desne izberite karticu SQL.

3. Ubacite ovaj kod i kliknite dugme "Go".





A Ako zelite da izmenite samo jedan red, npr., adresu kupca.

Primer 2:

update kupci
set adresa = 'Ivaniceva 29'
where sifrakupca = 4;

4. Izberite karticu SQL. dodajte ovaj kod i kliknite dugme "Go".






Except loading data from a database, some of them you will change. For example, you can increase the cost of the motobikes. To do this, use the UPDATE statement.

Syntax:

UPDATE table_name
SET column1=expression1,column2=expression2,...
[WHERE conditions]
[ORDER BY order]

[LIMIT some_number]

Explanation:

The point is that in the table table_name all of these columns be updated, depending on the given conditions. With the clause WHERE you can limit update to certain rows, and with clause LIMIT you can limit the total number of updated rows. ORDER BY clause is used only in combination with the clause LIMIT; for example, when you want to update only the first ten rows and first you want to align them in a specific order. Options LOW PRIORITY and IGNORE act in the same way as a statement INSERT.

If you want to increase the prices of all motobikes by 10%, you can use the  statement UPDATE without WHERE clause.

 Example:

UPDATE motobikes

SET price=price*1.1;

This file save as updating-records.sql.

1. Start XAMPP. Click on the Admin in line MySQL or type in the address bar http://localhost/phpmyadmin/

2. From the left select the database lovebikes, and on the right select the SQL tab.
3. Insert this code and click "Go".




And if you want to change a single row, eg., the customer's address.

Example 2:

UPDATE customers
SET address = 'Ivaniceva 83'

WHERE customerid = 4;

4. Select the tab SQL. add this code and click "Go".








No comments:

Post a Comment

Note: Only a member of this blog may post a comment.