Artificial Intelligence Design Innovation Machine Learning Technology

SQL CRUD Operations: Create, Read, Update and Delete.

Pinterest LinkedIn Tumblr

What is CRUD?

CRUD refers to the four basic operations a software application should be able to perform. These four operations are Create, Read, Update and Delete. When working with a database, you will need to use this sequel commands to get tasks done. You will need to create a database or a table, read the contents of your database, update your database or table and even drop or delete contents that are unnecessary to your database. Let us now take a look at each of these operations and how they work.

Create and Drop Database

You have just been hired to create and alter a database for a bookstore that has millions of books and is ever growing. How do you do this? Using Sequel Create and Read commands.

CREATE

To create a database, just type the CREATE DATABASE keyword followed by the name of your database and a semicolon. For Example:

CREATE DATABASE database_name;

DROP

To drop or delete a database, just type the keyword DROP and DATABASE followed by the name of the database you want to delete. For Example:

DROP DATABASE database_name;

Creating a Table in DBMS using Sequel Syntax.

Creating a database involves working with substantial amounts of data but how do you organise your data so that you can find exactly what you need. With sequel, you can create a table within your database to hold and organise your data. To do this, you start with the CREATE TABLE keyword, then the name of the table you want to create, then a pair of parenthesis. Within the parenthesis, you type the name of each column that must be included within the table followed by its respective datatype like:

ALSO READ  Procedural Programming in Python

CREATE TABLE table_name(column_name DATATYPE…);

Note: You must have a database to create a table from.

SQL ALTER Statement

No table is stagnant, it always needs restructuring, adding new columns, deleting old ones and so forth. You can do all these by using the sequel alter syntax. The first part of an alter statement is the ALTER and TABLE keyword. These inform the database that there is a table whose contents must be altered. This is followed by the name of the table to be altered. To add items, you then include the ADD keyword. This keyword tells sequel that there is one or more items to be added to the table. After this, you add a parentheses declaring the new column to be added and datatype and a semicolon. For example:

ALTER TABLE table_name ADD(column_name DATATYPE);

INSERT Statement

When working with databases, you will often have to add new rows and columns to existing tables or even create new tables from scratch. With sequel, you can perform the tasks quickly using the INSERT statements. We insert data into a table with the use of the INSERT INTO clause. To do this, you start with the INSERT INTO keyword then the name of the table you want to work on, then in parentheses, you input a pair of columns separated by a comma. After this, you write out the VALUES keyword then in a pair of parentheses, write out the values to be added to each column in correspondence to the columns. For example:

INSERT INTO table_name(column1_name, column2_name, column3_name) VALUES(value1, value2, value3);

ALSO READ  UI Frameworks and Libraries

You can also add multiple values. To do this, you do the following:

INSERT INTO table_name(column1_name, column2_name, column3_name) VALUES(value1, value2, value3), (value1, value2, value3), (value1, value2, value3);

Conclusion

In conclusion, we have covered the four basic operations every software application should be able to perform and also how to use them. These operations are essential tools for working with a database and navigating your way around them, so make it a goal to practice them well and get very familiar with it. Good luck!