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.
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.
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;
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 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:
CREATE TABLE table_name(column_name DATATYPE…);
Note: You must have a database to create a table from.
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);
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);
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);
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!
Introduction In the fast paced world of technology, learning a versatile and high-in-demand programming language…
Introduction User Authentication policy is a very crucial process for every application and organization. It…
Introduction In previous articles, we have learnt about Django, how it works and how we…
Introduction In this article, we shall learn how to build and implement a blog app.…
Introduction In this article, we shall use a database for the first time to build…
Introduction In this article, we will build a pages app that has a homepage and…