0% found this document useful (0 votes)
6 views3 pages

DDL_DML_DCL_operators

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)
6 views3 pages

DDL_DML_DCL_operators

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/ 3

1.

SQL Operators
SQL operators are symbols or keywords used to perform operations on data within an SQL query. They
are categorized into three main types:
a) Arithmetic Operators
These are used to perform mathematical operations on numeric data. The basic arithmetic operators in
SQL include:
 + (Addition) → Adds two numbers.
 - (Subtraction) → Subtracts the second number from the first.
 * (Multiplication) → Multiplies two numbers.
 / (Division) → Divides the first number by the second.
 % (Modulus) → Returns the remainder of the division.
b) Logical Operators
Logical operators are used to combine multiple conditions in SQL queries. The commonly used logical
operators are:
 ALL → Compares a value to all values in another set.
 AND → Returns true if both conditions are true.
 ANY → Compares a value to any value in a set.
 BETWEEN → Checks if a value lies within a range.
 EXISTS → Checks whether a subquery returns any rows.
c) Comparison Operators
Comparison operators are used to compare values in SQL queries. These include:
 = → Equal to
 != or <> → Not equal to
 > → Greater than
 < → Less than
 >= → Greater than or equal to
 <= → Less than or equal to
 !< → Not less than
 !> → Not greater than
2. SQL Datatypes
SQL datatypes define the type of data a column can store in a database. They are categorized into five
main types:
a) Exact Numeric
Used for storing precise numeric values.
 int → Integer (whole numbers).
 smallint → Smaller range of integers.
 bit → Boolean values (0 or 1).
 decimal → Fixed-point numbers with user-defined precision.
b) Approximate Numeric
Used for floating-point calculations where precision is not strict.
 float → Floating-point number.
 real → Similar to float but with lower precision.
c) Date and Time
Used to store date and time values.
 date → Stores only the date.
 time → Stores only the time.
 timestamp → Stores both date and time.
d) String Datatype
Used to store text data.
 char → Fixed-length string.
 varchar → Variable-length string.
 text → Large text data.
e) Binary Datatype
Used to store binary data such as images, files, and multimedia.
 binary → Fixed-length binary data.
 varbinary → Variable-length binary data.
 image → Stores large binary data like pictures or documents.
3. Types of SQL Commands
SQL commands are categorized into different types based on their functionality:
a) Data Definition Language (DDL)
Used to define and manage database structure.
 CREATE → Creates a new database object (table, index, etc.).
 ALTER → Modifies an existing object structure.
 DROP → Deletes a database object.
 TRUNCATE → Removes all records from a table but retains its structure.
b) Data Manipulation Language (DML)
Used to manipulate data stored in a database.
 SELECT (DQL) → Retrieves data from a database.
 INSERT → Adds new records.
 UPDATE → Modifies existing records.
 DELETE → Removes records from a table.
c) Data Control Language (DCL)
Used to control access and permissions in a database.
 GRANT → Gives user-specific privileges.
 REVOKE → Removes previously granted privileges.
d) Transaction Control Language (TCL)
Used to manage transactions in a database.
 COMMIT → Saves all changes made in a transaction.
 ROLLBACK → Reverts changes if an error occurs.

You might also like