In this section, you will learn more about the MySQL queries and it will also help you to improve your database query concepts.
You can create the MySQL database by using the below query:
1 | create database database_name; |
Use below MySQL query to create a MySQL table:
1 2 3 4 5 6 7 8 | CREATE TABLE tbl_employee( emp_id INT NOT NULL AUTO_INCREMENT, dept_id INT NOT NULL, emp_firstname VARCHAR(100) NOT NULL, emp_lastname VARCHAR(100) NOT NULL, emp_salary VARCHAR(100) NOT NULL, PRIMARY KEY (emp_id) ); |
Want to insert data in MySQL table, then use the below query:
1 2 | INSERT INTO employee(emp_id, emp_name, salary) VALUES (002, 'Amit Kumar', 30000); |
Use below code to delete the data from MySQL table.
1 2 | DELETE FROM employee WHERE emp_id = 6; |
Use below MySQL query to truncate MySQL table.
1 | TRUNCATE TABLE tbl_employee; |
Below is an example to fetch data from MySQL table by using the select query:
1 2 3 | SELECT emp_id, emp_name, emp_dept FROM employee WHERE emp_dept='HR'; |
Want to update the existing data in MySQL table, then use the below query to update the data in MySQL table.
1 2 3 | UPDATE employee SET emp_name = 'Ramesh Singh' WHERE emp_id = 12; |