CRUD?

According to Google, CRUD is defined as something which is considered disgusting or unpleasant or alternatively as nonsense. In relation to databases however, CRUD is an acronym that covers the basic operations that you can undertake on the database. These are:

Create - Adding new data to the database

Read - Accessing currently held information

Update - Modifying currently held data

Delete - Removing data

The most commonly used language to perform these actions on a database is SQL, which stands for Structured Query Language. This language has certain commands which map directly to the different CRUD elements. Some simple examples are:

CREATE TABLE student (id serial PRIMARY KEY, name varchar(80));  

This creates a database table "students" where we can carry out our operations. To create data we use the following basic command:

INSERT INTO students (id, name)  
VALUES (1, 'Jam3s');  

We have now created an entry in our database. But our name has a typo so we now want to update it.

UPDATE student SET name = 'James' WHERE id = 1  

Great! our entry is now exactly what we want but just to double check we want to read the entry from the database.

SELECT name FROM student WHERE id = 1  

James has now left the school so we need to remove him from the database. Our final operation should look like the following:

DELETE FROM student WHERE id = 1  

As a final note, you can see that the SELECT statement and the DELETE statement are pretty similar. Given the finality of the delete command it is always a good idea to carry out a select query first to make sure you are deleting what you think.