Website Development Prices

Search Blog

Saturday, November 21, 2015

Brisanje zapisa iz baze podataka (Deleting records from the database)

Za brisanje redova iz tabele sluzi iskaz delete

delete [low_priority] [quick] [ignore] from tabela
[where] uslov
[order by] kolone
[limit] broj

Napomena: ako napisete samo:

delete from tabela;

izbrisacete sve redove iz tabele, zato budite pazljivi.

Ako imate kupca koji dugo nista nije kupio, pa zelite da ga obrisete.

Primer:

delete from kupci

where sifrakupca=7;


Pomocu odredbe limit, mozete da zadate max. broj redova koji se brisu.
Odredba order by koristi se obicno u kombinaciji sa odredbom limit.
Odredbe low_priority i ignore deluju na isti nacin kao u drugim SQL komandama.
Odredba quick moze da ubrza obradu MyISAM tabela.

Ako zelite da obrisete celu tabelu.

Primer 2:

drop table tabela

Ako zelite da obrisete kolonu. Npr. kolonu pdv iz prethodnog clanka. 

alter table porudzbine

drop pdv;

Ako zelite da obriste celu bazu podataka.

Primer 3: 

drop database baza_podataka;

To delete rows from a table you can use DELETE statement.

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] from table
[WHERE] condition
[ORDER BY] column
[LIMIT] number

Note: if you write only:

DELETE FROM table;

you will delete all the rows from the table, so be careful.

If you have a customer who has not purchased anything for a long time, so you want to delete it.

Example:

DELETE FROM customers

WHERE customerid=7;

Using clause LIMIT, you may also specify the max. number of rows to be deleted.
ORDER BY clause is used usually in combination with the clause LIMIT.
The clause LOW_PRIORITY and IGNORE act in the same way as in other SQL commands.
The clause QUICK can accelerate processing of MyISAM tables.

If you want to delete the entire table.

Example 2:

DROP TABLE table;

If you want to delete the column. For example, a column of tax from the previous article.

ALTER TABLE orders

drop tax;

If you want to delete the whole database.


Example 3:

DROP DATABASE database;

No comments:

Post a Comment

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