0% found this document useful (0 votes)
9 views

doc 1

db 1

Uploaded by

renu.dandge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

doc 1

db 1

Uploaded by

renu.dandge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

DDL Commands: Data Definition Language


DDL commands are used to define and manage the structure of a database, such as creating
tables, altering schemas, and dropping objects.

1.1 CREATE Command

The CREATE statement is used to create a new table, database, index, or view.

Syntax for Creating a Table:

sql
Copy code
CREATE TABLE table_name (
column1 datatype CONSTRAINTS,
column2 datatype CONSTRAINTS,
...
);

Example:

sql
Copy code
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
HireDate DATE,
Salary DECIMAL(10, 2)
);

1.2 ALTER Command

The ALTER statement is used to modify the structure of an existing table, like adding, deleting,
or modifying columns.

Syntax for Adding a Column:

sql
Copy code
ALTER TABLE table_name
ADD column_name datatype;

Example:

sql
Copy code
ALTER TABLE Employees
ADD Email VARCHAR(100);

Syntax for Dropping a Column:

sql
Copy code
ALTER TABLE table_name
DROP COLUMN column_name;

Example:

sql
Copy code
ALTER TABLE Employees
DROP COLUMN Email;

1.3 DROP Command

The DROP statement is used to remove a table or database from the system permanently.

Syntax:

sql
Copy code
DROP TABLE table_name;

Example:

sql
Copy code
DROP TABLE Employees;

1.4 TRUNCATE Command

The TRUNCATE statement removes all rows from a table without logging individual row
deletions, making it faster than DELETE but irreversible.

Syntax:

sql
Copy code
TRUNCATE TABLE table_name;

Example:

sql
Copy code
TRUNCATE TABLE Employees;

2. DML Commands: Data Manipulation Language


DML commands are used to manipulate data within existing tables, such as inserting,
updating, and deleting records.

2.1 SELECT Command

The SELECT statement retrieves data from one or more tables.


Basic Syntax:

sql
Copy code
SELECT column1, column2, ...
FROM table_name;

Example:

sql
Copy code
SELECT FirstName, LastName, HireDate
FROM Employees;

SELECT with WHERE Clause:

sql
Copy code
SELECT *
FROM Employees
WHERE Salary > 50000;

2.2 INSERT Command

The INSERT statement is used to insert new rows of data into a table.

Syntax:

sql
Copy code
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

Example:

sql
Copy code
INSERT INTO Employees (EmployeeID, FirstName, LastName, HireDate, Salary)
VALUES (1, 'John', 'Doe', '2023-01-15', 60000);

Syntax for Inserting Multiple Rows:

sql
Copy code
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...),
(value3, value4, ...);

Example:

sql
Copy code
INSERT INTO Employees (EmployeeID, FirstName, LastName, HireDate, Salary)
VALUES
(2, 'Jane', 'Smith', '2023-05-10', 75000),
(3, 'Tom', 'Brown', '2023-07-01', 52000);

2.3 UPDATE Command

The UPDATE statement is used to modify existing records in a table.

Syntax:

sql
Copy code
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Example:

sql
Copy code
UPDATE Employees
SET Salary = 70000
WHERE EmployeeID = 1;

2.4 DELETE Command

The DELETE statement is used to remove rows from a table based on a condition.

Syntax:

sql
Copy code
DELETE FROM table_name
WHERE condition;

Example:

sql
Copy code
DELETE FROM Employees
WHERE EmployeeID = 2;

You might also like