Basic concept of database management system
a concept of a DBMS learner
In past two post we learn:
- how to show a database
- how to create a database
- how to show a table
- how to create a table
- how to insert data into table &
- how to see the data existing in a table
- How to update data in atable
Today we learn how to delete data from a table.
The DELETE statement is used to delete rows in a table. It's very simple. To delete any data in a table of a DBMS we follow the given syntax:
DELETE FROM table_name
WHERE some_column=some_value;
The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
To delete all data from a table we use following syntax:
DELETE FROM table_name;
We can insert data in a table. Today we learn how to delete data from a table. Before delete we want to insert some data to cheek that we can insert & after inserting we again delete those data. Let insert two more row in the table "Table_name".
DELETE FROM table_name;
or
DELETE * FROM table_name;
DELETE * FROM table_name;
Lets consider some example to get the concept clear. There are three data in the table "table_name" given below in a picture:
We can insert data in a table. Today we learn how to delete data from a table. Before delete we want to insert some data to cheek that we can insert & after inserting we again delete those data. Let insert two more row in the table "Table_name".
We know what to do to insert data in a table. It's look like below:
Insert into table_name values (4,'fata','fata@mail.com');
insert into table_name values (5,'sata','sata@mail.com');
Data is inserted & we get like following picture:
Wow! we can insert data into table & we must be able to delete data after a few moment. I don't want to spent anymore time. Lets start .....
Firstly we want to delete specific row/ rows from table. For this reason we have to follow the following rules:
DELETE FROM table_name
WHERE some_column=some_value;
One example can make the concept clear.If we want to delete id no 5 with its all records then we have to write:
delete from table_name where id='5';
If it shows a massage containing "Query Ok, 1 row affected (0.01 sec)" like following picture then we almost done mean we successfully delete that data.
Notice that the id no 5 & its all record is deleted. It clarify from the following picture:
Now again write delete from table_name where name='fata'; then it will delete the entire raw of id 4. And we get like following picture:
Here where clause mention data linking mean which data will be delete.
Now we learn delete entire data of a table. To do so we have to write:
delete from table_name;
or
delete * from table_name;
Write any one of two command to delete entire data from the table.
The above picture show that "Query Ok, 3 rows affected (0.01 sec) mean it delete three row of the table.
When we write select *from table_name; then it tells us Empty set (0.0 sec) mean all data deleted
Is it so tough? Obviously not. So keep trying.
No comments:
Post a Comment