0% found this document useful (0 votes)
87 views2 pages

DDL SQL Queries

The document outlines various DDL SQL statements including CREATE, ALTER, TRUNCATE, DROP, and RENAME for managing database tables. It provides examples for creating and modifying tables, as well as applying key constraints like PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK. Additionally, it demonstrates how to manage table structures and constraints effectively in SQL.

Uploaded by

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

DDL SQL Queries

The document outlines various DDL SQL statements including CREATE, ALTER, TRUNCATE, DROP, and RENAME for managing database tables. It provides examples for creating and modifying tables, as well as applying key constraints like PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK. Additionally, it demonstrates how to manage table structures and constraints effectively in SQL.

Uploaded by

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

DDL SQL Queries - Create, Alter, Truncate, Drop, Rename, and Constraints

1) DDL Statements

1) DDL STATEMENTS:

a) CREATE TABLE:
CREATE TABLE Employee (
EmpID INT,
Name VARCHAR(50),
Department VARCHAR(50),
Salary DECIMAL(10, 2)
);

b) ALTER TABLE:
-- Add a new column
ALTER TABLE Employee
ADD Email VARCHAR(100);

-- Modify an existing column


ALTER TABLE Employee
MODIFY Salary DECIMAL(12, 2);

-- Drop a column
ALTER TABLE Employee
DROP COLUMN Email;

c) TRUNCATE TABLE:
TRUNCATE TABLE Employee;

d) DROP TABLE:
DROP TABLE Employee;

e) RENAME TABLE:
-- Oracle Syntax
RENAME Employee TO Staff;

-- MySQL Syntax
ALTER TABLE Employee RENAME TO Staff;

2) Applying Key Constraints


DDL SQL Queries - Create, Alter, Truncate, Drop, Rename, and Constraints

2) APPLYING KEY CONSTRAINTS:

a) Create Department Table with PRIMARY KEY and NOT NULL:


CREATE TABLE Department (
DeptID INT PRIMARY KEY,
DeptName VARCHAR(50) NOT NULL
);

b) Create Employee Table with PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK:
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE,
Salary DECIMAL(10, 2),
DeptID INT,
FOREIGN KEY (DeptID) REFERENCES Department(DeptID),
CHECK (Salary > 10000)
);

You might also like