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

dbms-module3-chapter1

The document provides an overview of SQL categories in a Database Management System, including DDL, DML, DCL, TCL, and DQL. It explains various SQL operators such as AND, OR, and BETWEEN, along with examples for each. Additionally, it discusses the ORDER BY clause for sorting results and mentions the importance of handling ambiguous attribute names and constraints in SQL.

Uploaded by

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

dbms-module3-chapter1

The document provides an overview of SQL categories in a Database Management System, including DDL, DML, DCL, TCL, and DQL. It explains various SQL operators such as AND, OR, and BETWEEN, along with examples for each. Additionally, it discusses the ORDER BY clause for sorting results and mentions the importance of handling ambiguous attribute names and constraints in SQL.

Uploaded by

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

• In a Database Management System (DBMS), SQL (Structured Query Language) is

divided into different categories based on the type of operations that can be
performed on the data. These categories include DDL, DML, DCL, TCL, and DQL.
CREATE TABLE Employees (
EmployeeID INT PRIMARY
KEY,
Name VARCHAR(100),
Department
VARCHAR(50)
);
SQL supports a range of data types across widely used classes of data,
such as the following:

Numeric types
String or character types
Temporal types for dates and times
INSERT INTO Employees (EmployeeID, Name, Department) VALUES
(1, 'John Doe', 'HR');
1. AND OPERATOR
• The AND operator is used to combine two or more conditions in
the WHERE clause. It ensures that all the conditions must be true
for a row to be included in the result set. In other words, it performs
a logical AND operation between the conditions.
• Syntax:
SELECT column1, column2
FROM table_name
WHERE condition1 AND condition2;
• Example:
SELECT *
FROM Employees
WHERE Department = 'HR' AND Salary > 50000;
2. OR OPERATOR
• The OR operator is used to combine two or more conditions in
the WHERE clause. It ensures that at least one of the conditions must
be true for a row to be included in the result set. In other words, it
performs a logical OR operation between the conditions.
• Syntax:
SELECT column1, column2
FROM table_name
WHERE condition1 OR condition2;
• Example:
SELECT *
FROM Employees
WHERE Department = 'HR' OR Salary > 50000;
The SQL BETWEEN Operator
The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end values are included.

Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

Example:
Select all products with a price between 10 and 20:
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
• NOT BETWEEN
To display the products outside the range of the previous example,
use NOT BETWEEN.
Example
SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;

• BETWEEN with IN
The following SQL statement selects all products with a price
between 10 and 20. In addition, the CategoryID must be either 1,2,
or 3:
Example
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20
AND CategoryID IN (1,2,3);
THE SQL ORDER BY
• The ORDER BY keyword is used to sort the result-set in ascending or
descending order.
Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

Example: Sort the products by price:


SELECT * FROM Products
ORDER BY Price;
• DESC
The ORDER BY keyword sorts the records in ascending order by default. To
sort the records in descending order, use the DESC keyword.

• Example: Sort the products from highest to lowest price:


SELECT * FROM Products
ORDER BY Price DESC;

• Using Both ASC and DESC


• The following SQL statement selects all customers from the "Customers"
table, sorted ascending by the "Country" and descending by the
"CustomerName" column:
Example
SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;
AMBIGUOUS ATTRIBUTE NAMES, ALIASING,
RENAMING, AND TUPLE VARIABLES
AMBIGUOUS ATTRIBUTE NAMES, ALIASING,
RENAMING, AND TUPLE
VARIABLES(CONTD…)
AMBIGUOUS ATTRIBUTE NAMES, ALIASING,
RENAMING, AND TUPLE
VARIABLES(CONTD…)
ASSIGNMENT

• Learn the different Inserting with Constraints like- NOT NULL


Constraint, PRIMARY KEY Constraint, UNIQUE Constraint,
CHECK Constraint, DEFAULT Constraint, FOREIGN KEY
Constraint.

You might also like