MySQL SELECT Statement

MySQL SELECT Statement The MySQL SELECT statement is used to fetch data from the one or more tables in MySQL. We can retrieve records of all fields or specified fields. Syntax for specified fields: SELECT expressions FROM tables [WHERE conditions]; Syntax for all fields: SELECT * FROM tables [WHERE conditions]; MySQL SELECT Example 1: for specified fields In such case, it is mandatory … Read more

MySQL DELETE Statement

MySQL DELETE Statement MySQL DELETE statement is used to delete data from the MySQL table within the database. By using delete statement, we can delete records on the basis of conditions. Syntax: DELETE FROM table_name WHERE (Condition specified); Example: DELETE FROM cus_tbl WHERE cus_id = 6; Output:

MySQL UPDATE Query

MySQL UPDATE Query MySQL UPDATE statement is used to update data of the MySQL table within the database. In real life scenario, records are changed over the period of time. So, we need to make changes in the values of the tables also. To do so, we need to use the UPDATE statement. The UPDATE … Read more

MySQL INSERT Statement

MySQL INSERT Statement MySQL INSERT statement is used to insert data in MySQL table within the database. We can insert single or multiple records using a single query in MySQL. Syntax: The SQL INSERT INTO command is used to insert data in MySQL table. Following is a generic syntax: INSERT INTO table_name ( field1, field2,…fieldN ) VALUES ( value1, value2,…valueN ); Syntax for all … Read more

MySQL View

MySQL View In MySQL, View is a virtual table created by a query by joining one or more tables. MySQL Create VIEW A VIEW is created by SELECT statements. SELECT statements are used to take data from the source table to make a VIEW. Syntax: CREATE [OR REPLACE] VIEW view_name AS SELECT columns FROM tables [WHERE conditions]; Parameters: OR REPLACE: It is optional. … Read more

MySQL DROP Table

MySQL DROP Table MYSQL DROP table statement removes the complete data with structure. Syntax: DROP TABLE  table_name; Example: DROP TABLE  cus_tbl; MySQL TRUNCATE Table vs DROP Table You can also use DROP TABLE command to delete complete table but it will remove complete table data and structure both. You need to re-create the table again if you have to … Read more

MySQL TRUNCATE Table

MySQL TRUNCATE Table MYSQL TRUNCATE statement removes the complete data without removing its structure. The TRUNCATE TABLE statement is used when you want to delete the complete data from a table without removing the table structure. Syntax: TRUNCATE TABLE  table_name; Example: This example specifies how to truncate a table. In this example, we truncate the table “cus_tbl”. … Read more

MySQL ALTER Table

MySQL ALTER Table MySQL ALTER statement is used when you want to change the name of your table or any table field. It is also used to add or delete an existing column in a table. The ALTER statement is always used with “ADD”, “DROP” and “MODIFY” commands according to the situation. 1) ADD a … Read more

MySQL CREATE TABLE

MySQL CREATE TABLE The MySQL CREATE TABLE command is used to create a new table into the database. A table creation command requires three things: Name of the table Names of fields Definitions for each field Syntax: CREATE TABLE table_name (column_name column_type…); Example: Here, we will create a table named “cus_tbl” in the database “customers”. Note: Here, NOT NULL … Read more

MySQL Drop Database

MySQL Drop Database You can drop/delete/remove a MySQL database easily with the MySQL DROP DATABASE command. It deletes all the tables of the database along with the database permanently. Syntax: DROP DATABASE database_name; Example: Let’s take an example to drop a database name “employees” DROP DATABASE employees; Now you can check that either your database is removed by executing … Read more