/    /  MySQL – Queries

MySQL – Queries

 

The following is a list of commonly used MySQL queries for creating databases, using databases, creating tables, inserting records, updating records, deleting records, selecting records, truncating tables, and dropping tables.

Create Database:

The MySQL create database command is used to create a database.

 For example

create database employees;

Select/Use Database

The MySQL database is used to select the database.

 For example

use employees;

Create Query

The MySQL create query creates a table, view, procedure, and function.

 For example:

CREATE TABLE employees (
   id INT AUTO_INCREMENT PRIMARY KEY,
   first_name VARCHAR(30) NOT NULL,
   last_name VARCHAR(30) NOT NULL,
   email VARCHAR(50) UNIQUE NOT NULL,
   salary DOUBLE NOT NULL
);

Alter Query

A MySQL alter query adds, modifies, deletes, or drops columns from a table. Here is a query to add a column to the employees table:

ALTER TABLE employees  
ADD age varchar(50); 

Insert Query

When inserting records into a table, MySQL insert query is used. For example:

INSERT INTO  employees( first_name, last_name,email,salary) VALUES ('Ravi', 'V', 'ravi@gmail.com',100000);

Update Query

A MySQL update query is used to update records in a table. For example:

update customers set first_name=Sai, email=ravi@gmail.com where id=1; 

Delete Query

The update query in MySQL is used to delete records from a table in the database. For example:

delete from customers where id=101;  

Select Query

A select query is used to retrieve records from a database. For example:

SELECT * from employees;  

Truncate Table Query

In MySQL, an update query is used to truncate or remove records from a table. Structure is not removed by this process. For example:

truncate table employees;  

 Drop Query

The drop query in MySQL is used to delete a table, view, or database. In the event that you drop a table, its structure and data will be removed. For example:

drop table employees;