{"id":1712,"date":"2023-11-02T23:34:02","date_gmt":"2023-11-02T23:34:02","guid":{"rendered":"https:\/\/matob.web.id\/random\/?p=1712"},"modified":"2023-11-02T23:34:02","modified_gmt":"2023-11-02T23:34:02","slug":"query-sql","status":"publish","type":"post","link":"https:\/\/matob.web.id\/random\/query-sql\/","title":{"rendered":"What is Query SQL?"},"content":{"rendered":"<p><em>On this occasion we will discuss what is <a href=\"https:\/\/matob.web.id\/random\/technology\/query-sql\">Query SQL<\/a>. You can read it to the end to find out<\/em><\/p>\n<p><span>For those of you who are just getting to know databases or are just learning MySQL databases.\u00a0Must be familiar with the term query on the database.\u00a0This query is very familiar in database processing.<\/span><\/p>\n<p><span>However, what is a query?\u00a0Then, how to use <a href=\"https:\/\/matob.web.id\/random\/programming\/the-history-and-the-future-of-mysql\/\">MySQL database<\/a> queries?<\/span><\/p>\n<p><span>Come on!\u00a0Check out our article below!\u00a0Here we will thoroughly explain the explanation of database queries and the use of database queries in MySQL.<\/span><\/p>\n<h2><span>What are Query?<\/span><\/h2>\n<p><span>Query is a syntax or command used to access and display data in the database system.\u00a0Queries have the ability to set which data needs to be displayed the way you want.\u00a0In addition, queries can be used to make data interact with each other.\u00a0<\/span><\/p>\n<p><span>Query is also often referred to as a\u00a0<\/span><em><span>query language<\/span><\/em><span>.\u00a0Currently the most popular query language among Database Administrators is SQL.<\/span><\/p>\n<h2><span>Three Types of Database Query in SQL<\/span><\/h2>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-1715 size-full\" src=\"https:\/\/matob.web.id\/random\/wp-content\/uploads\/sites\/2\/2021\/12\/Query-SQL.jpg\" alt=\"Query SQL\" width=\"800\" height=\"450\" title=\"\" srcset=\"https:\/\/matob.web.id\/random\/wp-content\/uploads\/sites\/2\/2021\/12\/Query-SQL.jpg 800w, https:\/\/matob.web.id\/random\/wp-content\/uploads\/sites\/2\/2021\/12\/Query-SQL-768x432.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p><span>There are three types of database queries in SQL, namely:<\/span><\/p>\n<ul>\n<li><span>DDL (\u00a0<\/span><em><span>Data Definition Language\u00a0<\/span><\/em><span>)<\/span><\/li>\n<li><span>DML (\u00a0<\/span><em><span>Data Manipulation Language\u00a0<\/span><\/em><span>)<\/span><\/li>\n<li><span>DCL (\u00a0<\/span><em><span>Data Control Language\u00a0<\/span><\/em><span>).<\/span><\/li>\n<\/ul>\n<p><span>These three queries function to create\/define database objects such as creating tables, manipulating databases, and controlling databases.<\/span><\/p>\n<p><span>To be more complete, the following is an explanation of the three types of database queries.<\/span><\/p>\n<h3><span>1. DDL (\u00a0<\/span><em><span>Data Definition Language\u00a0<\/span><\/em><span>)<\/span><\/h3>\n<p><span>DDL is a SQL query method used to define data in a database.\u00a0With this query you can create new tables, modify tables, create indexes, define table storage structures and so on.\u00a0Following are the queries that DDL has:<\/span><\/p>\n<figure>\n<table>\n<tbody>\n<tr>\n<td><strong><span>Query Name<\/span><\/strong><\/td>\n<td><strong><span>description<\/span><\/strong><\/td>\n<\/tr>\n<tr>\n<td><span>CREATE<\/span><\/td>\n<td><span>Used to create databases and tables.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Drop<\/span><\/td>\n<td><span>Used to delete tables and databases.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>Alter<\/span><\/td>\n<td><span>Used to make changes to the table structure that has been created.\u00a0For example, adding a Field (\u00a0<\/span><strong><span>Add\u00a0<\/span><\/strong><span>), renaming a Field (\u00a0<\/span><strong><span>Change\u00a0<\/span><\/strong><span>) or renaming it (\u00a0<\/span><strong><span>Rename\u00a0<\/span><\/strong><span>), and deleting a Field (\u00a0<\/span><strong><span>Drop\u00a0<\/span><\/strong><span>).<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><span>2. DML (\u00a0<\/span><em><span>Data Manipulation Language\u00a0<\/span><\/em><span>)<\/span><\/h3>\n<p><span>DML is a query method that is used when the DDL has been created.\u00a0i This DML query is used to manipulate the database.\u00a0The following are the queries that DML has:<\/span><\/p>\n<figure>\n<table>\n<tbody>\n<tr>\n<td><strong><span>Query Name<\/span><\/strong><\/td>\n<td><strong><span>description<\/span><\/strong><\/td>\n<\/tr>\n<tr>\n<td><span>INSERT<\/span><\/td>\n<td><span>Used to enter data in database tables.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>UPDATE<\/span><\/td>\n<td><span>Used to modify existing data in database tables.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>DELETE<\/span><\/td>\n<td><span>Used to delete data in a database table.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3><span>3. DCL (\u00a0<\/span><em><span>Data Control Language\u00a0<\/span><\/em><span>)<\/span><\/h3>\n<p><span>DCL is a SQL query method that is used to provide database access authorization rights, audit database usage, space allocation, and space definition.\u00a0Following are the queries that DCL has:<\/span><\/p>\n<figure>\n<table>\n<tbody>\n<tr>\n<td><strong><span>Query Name<\/span><\/strong><\/td>\n<td><strong><span>description<\/span><\/strong><\/td>\n<\/tr>\n<tr>\n<td><span>GRANT<\/span><\/td>\n<td><span>Used to allow users to access tables in the database.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>REVOKE<\/span><\/td>\n<td><span>Used to cancel user rights permissions.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>COMMIT<\/span><\/td>\n<td><span>Used to specify database storage.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span>ROLLBACK<\/span><\/td>\n<td><span>Used to cancel database save.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h2><span>Example of Using Database Query<\/span><\/h2>\n<p><span>In this guide, we will provide some basic guidelines for using database queries in MySQL Database.\u00a0For this tutorial we are using an Ubuntu 16.04 VPS server that has MySQL installed.\u00a0The following is an example of using a database query.<\/span><\/p>\n<h3><span>1. Creating a Database<\/span><\/h3>\n<p><span>The database is the main medium for building a database.\u00a0In this database later you can put some tables.\u00a0The following are the commands used to create a MySQL database:<\/span><\/p>\n<pre><code>\r\n\t\tcreate database database_name;\r\n\t<\/code><\/pre>\n<p><span>In the example above,\u00a0<\/span><strong><span>Query OK\u00a0<\/span><\/strong><span>shows the creation of a database with the name\u00a0<\/span><strong><span>office\u00a0<\/span><\/strong><span>successfully created.\u00a0To view existing databases in MySQL, you can use the following command:<\/span><\/p>\n<pre><code>\r\n\t\tshow databases;\r\n\t<\/code><\/pre>\n<p><span>Then the output of the above command will display a collection of databases on your server.\u00a0Here is a picture of the command above.<\/span><\/p>\n<h3><span>2. Delete Database<\/span><\/h3>\n<p><span>To delete a database that has been created, you can use the following SQL query command:<\/span><\/p>\n<pre><code>\r\n\t\tdrop database database_name;\r\n\t<\/code><\/pre>\n<p><span>Drop means delete.\u00a0This SQL query command serves to delete a database, as in the example in the following image:<\/span><\/p>\n<h3><span>3. Creating a Table<\/span><\/h3>\n<p><span>Tables are objects that are used to store all data in the database.\u00a0Therefore, the table is an object that must exist in the database.\u00a0<\/span><\/p>\n<p><span>The table is located in a database, so the table creation is done after a database has been created.\u00a0In a table there are rows and columns.\u00a0Rows are called\u00a0<strong><em>recordsets\u00a0<\/em><\/strong>while columns are called\u00a0<strong><em>fields\u00a0<\/em><\/strong>.<\/span><\/p>\n<p><span>To create a table or more, the database must be activated first.\u00a0Because the table will be inserted into the database that has been active.\u00a0Here is the command to enable Database:<\/span><\/p>\n<pre><code>\r\n\t\tuse database_name;\r\n\t<\/code><\/pre>\n<p><span>After logging into the database, you can create one or more tables.\u00a0To create a table, you can use the command below:<\/span><\/p>\n<pre><code>\r\n\t\tcreate table identity (no int(3),name varchar(35),address varchar(60),pisi varchar(40),phone_number varchar(15),);\r\n\t<\/code><\/pre>\n<p><span>In the example above,\u00a0<\/span><strong><span>Query OK\u00a0<\/span><\/strong><span>states that the creation of a table with the name\u00a0<\/span><strong><span>identity was <\/span><\/strong><span>successfully created.\u00a0To view the existing tables in the database, you can use the following command:<\/span><\/p>\n<pre><code>\r\n\t\tshow tables;\r\n\t<\/code><\/pre>\n<h3><span>4. View Table Structure<\/span><\/h3>\n<p><span>After the table is created, you can view the data type and length of the\u00a0<\/span><strong><span>recordset\u00a0<\/span><\/strong><span>by displaying the table structure.\u00a0The command used to display the table structure is as follows:\u00a0<\/span><\/p>\n<pre><code>\r\n\t\tdesc table_name;Ataudescribe table_name;\r\n\t<\/code><\/pre>\n<p><span>Then the output will be like in the image below:<\/span><\/p>\n<h3><span>5. Delete Table<\/span><\/h3>\n<p><span>To delete a table that has been created, you can use the SQL query command:\u00a0<\/span><strong><span>DROP.\u00a0<\/span><\/strong><span>Here&#8217;s an example:<\/span><\/p>\n<pre><code>\r\n\t\tdrop table table_name;\r\n\t<\/code><\/pre>\n<h3><span>6. Entering Data into Tables<\/span><\/h3>\n<p><span>To enter data, you must first have a table in the database.\u00a0Then, enter data or data entry with the\u00a0<\/span><strong><span>INSERT\u00a0<\/span><\/strong><span>command\u00a0.\u00a0All programs that use SQL queries use the same standard commands.\u00a0<\/span><\/p>\n<p><span>\u00a0Here&#8217;s an example of when the\u00a0<\/span><strong><span>INSERT\u00a0<\/span><\/strong><span>command is\u00a0used:<\/span><\/p>\n<pre><code>\r\n\t\tinsert into identity values('001','William','New York','SEO Team','026135998789');\r\n\t<\/code><\/pre>\n<p><span>To view the results of the data that has been entered in the table, use the following command:<\/span><\/p>\n<pre><code>\r\n\t\tselect * from table_name;\r\n\t<\/code><\/pre>\n<h3><span>7. Updating Data Content<\/span><\/h3>\n<p><span>If you need to update the contents of the data or update the data, use the SQL query command used is\u00a0<\/span><strong><span>UPDATE\u00a0<\/span><\/strong><span>.<\/span><\/p>\n<pre><code>\r\n\t\tupdate identity set name='Angelina Schmidt' where name=\"William\";\r\n\t<\/code><\/pre>\n<p><span>When you check the table, the data will change as in the image below:<\/span><\/p>\n<h3><span>8. Delete Data<\/span><\/h3>\n<p><span>To delete data, MySQL has a query named\u00a0<\/span><strong><span>DELETE\u00a0<\/span><\/strong><span>.\u00a0To use this query, you need to add the name of the data to be deleted.\u00a0If you want to delete all the data contained in the table, here&#8217;s the command:<\/span><\/p>\n<pre><code>\r\n\t\tdelete from table_name;\r\n\t<\/code><\/pre>\n<p><span>If you want to delete certain data from a table, the following syntax is used:<\/span><\/p>\n<pre><code>\r\n\t\tDELETE FROM table_name WHERE condition;\r\n\t<\/code><\/pre>\n<p><span>To delete data with id number 3 contained in the data_diri table, use a query as below:<\/span><\/p>\n<pre><code>\r\n\t\tdelete from identity where no='3';<\/code>\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>On this occasion we will discuss what is Query SQL. You can read it to the end to find out For those of you who are just getting to know databases or are just learning MySQL databases.\u00a0Must be familiar with the term query on the database.\u00a0This query is very familiar in database processing. However, what [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1716,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[173,78,179],"class_list":["post-1712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-database","tag-server","tag-sql"],"_links":{"self":[{"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/posts\/1712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/comments?post=1712"}],"version-history":[{"count":1,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/posts\/1712\/revisions"}],"predecessor-version":[{"id":2404,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/posts\/1712\/revisions\/2404"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/media\/1716"}],"wp:attachment":[{"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/media?parent=1712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/categories?post=1712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/matob.web.id\/random\/wp-json\/wp\/v2\/tags?post=1712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}