• HOME
  • VIDEO
  • COURSES
    • Java Expertise
      • Java SE(Core)
      • Java EE(Advance)
      • Servlet & JSP
      • EJB & Web Services
      • JMS & Java Mail
    • Java Framework Expertise
      • Spring Framework
      • Spring MVC
      • Hibernate Framework
      • Struts/Struts2 Framework
      • JSF
    • Mobile Expertise
      • Android
      • PhoneGap
      • HTML5
      • Bootstrap
    • Training Options
      • MCA Industrial Training
      • Corporate Training
      • Internship Programs
      • Online Training
      • Major and Minor Project Training
      • Project Work (Live Project)
    • PHP Expertise
      • PHP Core
      • PHP Advanced
      • WordPress
      • Drupal
    • Web Designing Expertise
      • HTML
      • JavaScript
      • Jquery
      • AJAX
    • Others
      • MySQL
      • Software Testing
      • XML Technologies
      • Agile Methodology
  • ABOUT
  • INSIGHTS
    • Column 1
      • Testimonials/Reviews
      • Share your feedback
      • Placement
      • Career
      • News & Events
      • Project Topics – reference
      • Site Map
      • Terms and Conditions(Global)
    • Column 2
      • Registration
      • Login
      • Inquiry
      • Please Call or Fill Enquiry Detail Below
      • Video Library – Free
      • Official Website
      • Business Blog
  • BLOG
    • Column 1
      • Java SE
      • Java EE
      • Spring Framework
      • Hibernate
      • Struts
    • Column 2
      • Android
      • Project Work
      • AJAX
      • JQuery
  • CONTACT
A Training Division of eZeon Technosolutions Pvt. Ltd.
Contact
Pay & Registration
EZEON - Training Division | Best For Java | Spring Framework | Spring Boot | Android | Major/Minor Projects | Live Projects | Internship |  Python |  Flutter | artificial intelligence | Bhopal EZEON - Training Division | Best For Java | Spring Framework | Spring Boot | Android | Major/Minor Projects | Live Projects | Internship |  Python |  Flutter | artificial intelligence | Bhopal
  • HOME
  • VIDEO
  • COURSES
    • Java Expertise
      • Java SE(Core)
      • Java EE(Advance)
      • Servlet & JSP
      • EJB & Web Services
      • JMS & Java Mail
    • Java Framework Expertise
      • Spring Framework
      • Spring MVC
      • Hibernate Framework
      • Struts/Struts2 Framework
      • JSF
    • Mobile Expertise
      • Android
      • PhoneGap
      • HTML5
      • Bootstrap
    • Training Options
      • MCA Industrial Training
      • Corporate Training
      • Internship Programs
      • Online Training
      • Major and Minor Project Training
      • Project Work (Live Project)
    • PHP Expertise
      • PHP Core
      • PHP Advanced
      • WordPress
      • Drupal
    • Web Designing Expertise
      • HTML
      • JavaScript
      • Jquery
      • AJAX
    • Others
      • MySQL
      • Software Testing
      • XML Technologies
      • Agile Methodology
  • ABOUT
  • INSIGHTS
    • Column 1
      • Testimonials/Reviews
      • Share your feedback
      • Placement
      • Career
      • News & Events
      • Project Topics – reference
      • Site Map
      • Terms and Conditions(Global)
    • Column 2
      • Registration
      • Login
      • Inquiry
      • Please Call or Fill Enquiry Detail Below
      • Video Library – Free
      • Official Website
      • Business Blog
  • BLOG
    • Column 1
      • Java SE
      • Java EE
      • Spring Framework
      • Hibernate
      • Struts
    • Column 2
      • Android
      • Project Work
      • AJAX
      • JQuery
  • CONTACT

Blog

MySQL Queries for Beginner – Quick Start

Feb 4, 2015 | Posted by Vikram Thakur | Database |

Please read below MySQL specific queries for reference. These are just quick start queries.

Connect to server (another way to connect to server from command prompt)

MySQL
1
mysql -h localhost -u root -p

List all the databases running in server

MySQL
1
show databases;

Creating new database

MySQL
1
create database mydb;

Select database to work on

MySQL
1
use mydb;

List all the tables from selected database

MySQL
1
show tables;

Create new table

MySQL
1
2
3
create table emp(id int, name varchar(50),salary float(10,2));
OR
create table emp(empId int(10) primary key auto_increment, name varchar(30), salary float(10,2));

Describe table

MySQL
1
2
3
desc emp;
OR
describe emp;

Insert record into table

MySQL
1
insert into emp(id,name,salary) values(5,'Vikram Thakur',5000.50);

Select all columns and all rows

MySQL
1
select * from emp;

Find selected columns and all rows

MySQL
1
select id, name from emp;

Find selected column and selected rows

MySQL
1
select id, name, salary from emp  where id>3;

Find data in range (between)

MySQL
1
select * from emp where id between 1 and 3;

Find selected columns and all rows

MySQL
1
select id, name from emp;

Find data in from given option (in)

MySQL
1
select * from emp where id in(1,5);

Find values other then given values (not in)

MySQL
1
select * from emp where id not in(1,3);

Equal condition

MySQL
1
select * from emp where name='Raj';

SQL Function Max

MySQL
1
select max(salary) from emp;

SQL Function MIN

MySQL
1
select min(salary) from emp;

SQL Function AVG

MySQL
1
select avg(salary) from emp;

Pattern query(like) : % and _ : wild card char

MySQL
1
2
3
4
5
6
7
8
9
10
11
12
select * from emp where name like('R%');
% : any char, n-number of chars, no char
 
_ (underscore) : any single char
Patterns for like :
name like('A%');
name like('%t');
name like('_a%')
like('_ _ j%r')
like('_ _j%a');
select * from emp where name like('%r');
select * from emp where name like('_a%r');

Update Record Query

MySQL
1
2
update emp set name='Raj Sinha' where id=1;
update emp set name='Raj Sinha', salary=50000 where id=1;

Delete all records

MySQL
1
DELETE FROM emp;

Delete records for match condition

MySQL
1
DELETE FROM emp WHERE empId=101;

Drop Table

MySQL
1
DROP TABLE emp;

Drop Database

MySQL
1
DROP DATABASE mydb;

Alter Table by modifying a column(resize name column)

MySQL
1
ALTER TABLE emp MODIFY name VARCHAR(80);

Alter Table by adding a column

MySQL
1
ALTER TABLE emp ADD address VARCHAR(150);

Alter Table by dropping a column

MySQL
1
ALTER TABLE emp DROP address;

Truncate table(drop and recreate structure)

MySQL
1
TRUNCATE TABLE emp;

Take MySql database backup for all databases

MySQL
1
D:\>mysqldump -u root -p --all-databases > backupall.sql

Thank you for reading.

Tags: Alterconditional queriesCreateDeleteDroplike queryMySQL CommandsMySQL Queriespattern querysql functiontruncateUpdate
10
Share

About Vikram Thakur

A Software Professional with extensive experience in IT industry and passionate about Java/J2EE, Spring and open source technologies. Always love to share knowledge. Please connect on


Recent Posts

  • Spring Framework and Hibernate Workshop
  • Free Training Video Session by EZEON
  • 10 Great Benefits to Choose Spring Web MVC Framework
  • Spring Web MVC Framework Tutorial – Best from Experts
  • MySQL Queries for Beginner – Quick Start

Categories

  • AJAX
  • Android
  • Cloud Computing
  • Database
  • Hibernate
  • HTML
  • Interview Questions
  • Java EE
  • Java SE
  • JavaScript
  • JQuery
  • JSP
  • Miscellaneous
  • Project Work
  • Servlet
  • Spring Framework
  • Spring Workshop
  • Struts
  • Video Library
  • Web Services
Learn from the Experts and Experience Best Practices of Software Industry

Please write us today

Get In Touch
EZEON is a Software Development Company wish to share our Experience with Students, Developers and Companies to help them in adopting best practices. Its our small contribution towards skill development initiative

© 2023 - eZeon Technosolutions Pvt. Ltd.

  • Home
  • About
  • Courses
  • Blog
  • Site Map
  • Terms & Conditions
Prev Next