Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
MySQL Interview Questions
Next article icon

CRUD Operations in MySQL

Last Updated : 30 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

As we know that we can use MySQL to use Structure Query Language to store the data in the form of RDBMS. SQL is the most popular language for adding, accessing, and managing content in a database. It is most noted for its quick processing, proven reliability, ease, and flexibility of use. The application is used for a wide range of purposes, including data warehousing, e-commerce, and logging applications. The most common use for MySQL, however, is for the purpose of a web database. 

MySQL provides a set of some basic but most essential operations that will help you to easily interact with the MySQL database and these operations are known as CRUD operations. 

 

1. Create Table Command : 

Syntax : 
 

CREATE TABLE table_name (column_name column_type constraints);

Parameters : 
 

  1. column_name – 
    Name of the particular column with any space.
  2. column_type – 
    Datatype of the column. Datatype depends upon the data of the reference column. Datatype can be – char(), varchar(), int(), float(), etc.
  3. constraints – 
    In order to give restrictions to particular column constraints are used. Constraints can be – not null, primary key, foreign key, etc. These are the keywords which give set of restriction to the particular column.

Database – GFG 
Table – Student 
Student – 
 

  • name Varchar(30) NOT NULL
  • marks Integer

Example : 
use <database> command must be used before any operation on the table. 

 

use gfg; Create table student(name Varchar(30) NOT NULL, marks Integer);

Output : 

 

Field Type Null Default
name varchar(30) No Null
marks int(11) YES Null

2. Read Operation : 
The Read operations are used to retrieve the content of the table from a particular database. Read operation is done by DDL commands. 

Example : 
 

use gfg; select * from student;

 

name marks
ravi 23
swati 33
kranti 12

3. Update Operation : 
Altering the content of the table or the structure of the table is done with the help of Update Operations. Two Commands are mostly used for Update Operation – 
 

  1. Alter Table Command – 
    This is the DDL command (Data Definition Language) used to change the structure of the table. 

     

  2. Update Table Command – 
    This is the DML command(Data Manipulating Language) used to alter the records. 

     

Alter Table Command that change the size of name column from varchar(40) to varchar(50) for the Student table : 

 

Alter table student  modify name varchar(50) not null;

Original Table – 
 

desc student;

 

Field Type Null Default
name 
marks 
 
varchar(40) 
int(11) 
 
YES 
YES 
 
Null 
Null 
 

After altering the table – 
 

desc student;

 

Field Type Null Default
name 
marks 
 
varchar(50) 
int(11) 
 
YES 
YES 
 
Null 
Null 
 

Update Command that update the marks of the student from 23 to 100 whose name is ravi using the update command : 

 

Update student set marks = 100  where name = "ravi";

Original Table – 
 

select * from student;

 

name marks
ravi 23
swati 33
kranti 12

After updating the table – 
 

select * from student;

 

name marks
ravi 100
swati 33
kranti 12

4. Delete Operation : 
Two commands are mostly used for the Delete operations – 
 

  1. Delete Command – 
    (DML command) works on the records of the table. 

     

  2. Drop Command – 
    (DDL command) works on the structure of the table. 
     

Delete Command that delete the records of students having marks equal to 100 : 

 

delete from student  where marks = 100;

Original Table – 
 

select * from student;

 

name marks
ravi 100
swati 33
kranti 12

After deleting the student records – 
 

select * from student;

 

name marks
swati 33
kranti 12

Drop Command that drop the table student : 

 

drop table student;

Original Structure – 
 

use gfg; show tables;

 

Tables_in_gfg
student

After dropping the student table – 
 

use gfg; show tables;

 

Tables_in_gfg
 

 



Next Article
MySQL Interview Questions
author
zack_aayush
Improve
Article Tags :
  • SQL
  • DBMS-SQL
  • mysql
  • Technical Scripter 2020

Similar Reads

  • PHP - MySQL min(),max() aggregate operations
    In this article, we are going to find minimum and maximum details from the table column using PHP from MySQL Xampp server. We are taking an example from employee database to find the minimum and maximum salary of the employee. Requirements -Xampp server Introduction : PHP - It stands for Hyper Text
    4 min read
  • PHP - MYSQL : sum() operation
    Problem Statement: In this article, we are going to perform sum() aggregate operation on our database using PHP with xampp server. So we are considering the food_order database and perform database sum() operation. Requirements: xampp Introduction: PHP stands for hypertext preprocessor which is a se
    3 min read
  • Python MySQL - BETWEEN and IN Operator
    In this article, we are going to see the database operations BETWEEN and IN operators in MySQL using Python. Both of these operators are used with the WHERE query to check if an expression is within a range or in a list of values in SQL. We are going to use the below table to perform various operati
    3 min read
  • PERIOD_ADD() function in MySQL
    PERIOD_ADD() function in MySQL helps to add a specific number of months to a given period. The PERIOD_ADD() function will return the resultant value in 'YYYYMM' format. Syntax : PERIOD_ADD(period, number) Parameters : period - A period which should be in YYMM OR YYYYMM format. number - The number of
    1 min read
  • MySQL Interview Questions
    MySQL is an open-source Relational Database Management System(RDMS) that organizes data in tables using rows and columns. It uses Structured Query Language (SQL) for managing and manipulating databases. It was originally developed by MySQL AB, a Swedish company, and is now owned by Oracle Corporatio
    15 min read
  • POWER() Function in MySQL
    POWER() function in MySQL is used to find the value of a number raised to the power of another number. It Returns the value of X raised to the power of Y. Syntax : POWER(X, Y) Parameter : This method accepts two parameter which are described below : X : It specifies the base number. Y : It specifies
    3 min read
  • TAN() Function in MySQL
    TAN() function : This function in MySQL is used to return the tangent of a specified number. In any right triangle, the tangent of an angle is the length of the opposite side divided by the length of the adjacent side. Similarly, this can also be defined as tangent of x is the sine of x divided by t
    1 min read
  • OCT() function in MySQL
    OCT() function in MySQL is used to convert decimal number to octal. It returns equivalent octal value of a decimal number. Syntax : OCT(number) Parameter : This method accepts only one parameter. number : The decimal number which we want to convert. Returns : It returns octal value of a decimal numb
    2 min read
  • MySQL | Operator precedence
    Operator precedence specifies the order in which operators are evaluated when two or more operators with different precedence are adjacent in an expression. For example, 1+2/3 gives the different result as compared to (1+2)/3. Just like all other programming languages C, C++, Java etc. MySQL also ha
    3 min read
  • SQRT() Function in MySQL
    The SQRT() function in MySQL calculates the square root of a non-negative number, returning NULL for negative inputs. It is a built-in function that provides high precision and is optimized for performance and making it ideal for mathematical and scientific applications. In the article, we will cove
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences