DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • SQL Commands: A Brief Guide
  • SQL Query Performance Tuning in MySQL: Part 2
  • The Ultimate Guide To Repair MySQL Database
  • SQL Query Performance Tuning in MySQL

Trending

  • Memory Leak Due to Time-Taking finalize() Method
  • Building a Real-Time Audio Transcription System With OpenAI’s Realtime API
  • Using Java Stream Gatherers To Improve Stateful Operations
  • Proactive Security in Distributed Systems: A Developer’s Approach
  1. DZone
  2. Data Engineering
  3. Databases
  4. An Introduction to DDL, DML, and DCL Commands in MySQL: A Comprehensive Guide With Examples

An Introduction to DDL, DML, and DCL Commands in MySQL: A Comprehensive Guide With Examples

This article delves into each category of MySQL commands and their practical applications, providing definitions and illustrative examples.

By 
Vijay Panwar user avatar
Vijay Panwar
DZone Core CORE ·
Feb. 22, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
3.8K Views

Join the DZone community and get the full member experience.

Join For Free

MySQL is widely recognized as one of the most popular open-source relational database management systems. It holds immense significance in the realm of web development, data analytics, and beyond. Its adaptability and user-friendly nature have positioned it as the preferred choice for managing structured data. 

MySQL commands are classified into various types, primarily based on their purpose within the database. These types encompass Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL). A comprehensive understanding of these commands and their practical applications is essential for individuals involved in MySQL database operations. This article delves into each category, offering precise definitions and illustrative examples to enhance comprehension.

Data Definition Language (DDL)

DDL commands are utilized to establish, modify, or eliminate the framework of the database entities, such as tables, indexes, and schemas. These commands do not manipulate the actual data but rather determine the organization of data within the database. Some typical DDL commands are CREATE, ALTER, DROP, TRUNCATE, and RENAME.

DDL Command Examples

1. CREATE - This command is used to create a new table in the database.

CREATE TABLE students (
student_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
enrollment_date DATE
last_update CAST(GETDATE() AS DATE)
);


2. ALTER - Used to modify an existing table, such as adding a new column or changing a data type:

ALTER TABLE students ADD email VARCHAR(255);


3. DROP - Removes the existing table and its data:

DROP TABLE students;


4. TRUNCATE - Deletes all data from a table without removing the table itself:

TRUNCATE TABLE students;


5. RENAME - Changes the name of a table

RENAME TABLE students TO alumni;


Data Manipulation Language (DML)

DML commands are used for managing data within table objects. This includes inserting, updating, deleting, and selecting data. DML commands directly affect the data itself, making them essential for everyday database operations. The primary DML commands are INSERT, UPDATE, DELETE, and SELECT.

DML Command Examples

1. INSERT - Adds new rows of data to a table:

INSERT INTO students (name, enrollment_date) VALUES ('Author Name', '1984-09-01');


2. UPDATE - Modifies existing data in a table:

UPDATE students SET email = 'john.doe@example.com' WHERE student_id = 1;


3. DELETE - Removes rows from a table:

DELETE FROM students WHERE student_id = 1;


4. DELETE, multiple students - Removes multiple rows from a table:

DELETE FROM students WHERE student_id between 2 and 6;


5. SELECT - Retrieves all data from one table:

SELECT * FROM students;


6.  SELECT - Select data between the student_id:

SELECT * FROM students where student_id between 5 and 8;


Data Control Language (DCL)

DCL commands primarily revolve around managing permissions and controlling access to database objects. These commands play a vital role in upholding database security by limiting access exclusively to authorized users. The two commonly used DCL commands are GRANT and REVOKE.

DCL Command Examples

1. GRANT - Gives a user permission to perform specific actions on database objects:

GRANT SELECT, INSERT ON students TO 'author@email.com';


2. REVOKE - Removes specific permissions from a user:

REVOKE INSERT ON students FROM 'author@email.com';


Conclusion

Mastering the utilization of DDL, DML, and DCL commands in MySQL is crucial for proficiently creating and administering databases, manipulating data as required, and guaranteeing secure control over data access. A comprehensive understanding of these commands is essential for harnessing the complete capabilities of MySQL in any data-centric application or system.

Control Language Data definition language Data manipulation language MySQL Command (computing)

Opinions expressed by DZone contributors are their own.

Related

  • SQL Commands: A Brief Guide
  • SQL Query Performance Tuning in MySQL: Part 2
  • The Ultimate Guide To Repair MySQL Database
  • SQL Query Performance Tuning in MySQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!