Delete Records from SQL Table

To delete the records from a table we use the "delete" command.


Basic syntax of delete in SQL:

 delete from TABLENAME;


The delete command is placed followed by the keyword "from" and the name of the table from which we want to delete the records. The following example removes the records from the "users" table:


delete from users;


Then a message indicates the number of records that have been deleted.

If we do not want to delete all the records, but only some, we must indicate which or which ones; For this we use the "delete" command together with the "where" clause with which we establish the condition that the records to be deleted must meet.


For example, we want to delete that record whose username is "Marcelo":


 delete from users

 where name = 'Marcelo';


If we request the deletion of a record that does not exist, that is, no record meets the specified condition, a message will appear indicating that no record was removed, as there were no records with that data.


Note that if we don't put in a condition, all records in the specified table are dropped.

Comments

Popular posts from this blog

Data Consistency and Inconsistency - What is Difference

Cardinality in DBMS – max/minimum cardinality & examples

Relational Model in DBMS