Coding Schools


 
Python | C Sharp | Azure AI | HTML | JavaScript | CSS | SQL Server
Normalization in SQL Server
DDL and DML in SQL Server
SQL Server System Databases
SQL Server System Tables
Joins in SQL Server
SQL Server - Indexes
CTE in SQL Server
SQL Server - Locks
Optimization Techniques in SQL Server
How to Setup NDF Files in SQL Server
Deadlocks in SQL Server
Transactions in SQL Server
Difference UDF vs Stored Procedure
SQL Server Triggers
SQL Server Isolation Levels
SQL Server Pivot Tables
SQL Server - Group By Statement
SQL Server - Find Second highest Number Query
SQL Server - Recursion in User Defined Function
SQL Server Error Handling
Difference Table Variable and Temporary Table
SQL Server - Temporal Tables
User Defined Functions - SQL Server
Stored Procedures - SQL Server

DDL and DML in SQL Server



DDL (Data Definition Language) and DML (Data Manipulation Language) are two key subsets of SQL (Structured Query Language) that serve different purposes. Here's a breakdown:

Data Definition Language (DDL):

DDL statements are used to define and manage database structures such as tables, indexes, and schemas. Common DDL statements include:

  1. CREATE: Creates a new table, view, or other database objects.

    • Example: CREATE TABLE Employees (ID int, Name varchar(100), Age int);

  2. ALTER: Modifies an existing database object, such as adding a column to a table.

    • Example: ALTER TABLE Employees ADD Salary decimal(10, 2);

  3. DROP: Deletes an entire table, view, or another database object.

    • Example: DROP TABLE Employees;

  4. TRUNCATE: Removes all rows from a table without logging individual row deletions.

    • Example: TRUNCATE TABLE Employees;

Data Manipulation Language (DML):

DML statements are used to manipulate data within existing database objects. Common DML statements include:

  1. SELECT: Retrieves data from one or more tables.

    • Example: SELECT * FROM Employees;

  2. INSERT: Adds new rows of data to a table.

    • Example: INSERT INTO Employees (ID, Name, Age) VALUES (1, 'John Doe', 30);

  3. UPDATE: Modifies existing data within a table.

    • Example: UPDATE Employees SET Age = 31 WHERE ID = 1;

  4. DELETE: Removes existing data from a table.

    • Example: DELETE FROM Employees WHERE ID = 1;

Each type of statement serves a unique role in managing and manipulating the data and structure of databases. Is there a specific DDL or DML query you'd like to see in action or need further explanation on?




All rights reserved | Privacy Policy | Sitemap