0% found this document useful (0 votes)
10 views5 pages

Day 2 Notes

Excel

Uploaded by

cocomelon1650
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)
10 views5 pages

Day 2 Notes

Excel

Uploaded by

cocomelon1650
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/ 5

What is SQL?

SQL is a database language designed for the retrieval and management


of data in a relational database.

It was initially known as the structured English query language (SEQUEL).

SQL is the standard language for database management. All the RDBMS
systems like MySQL, MS Access, Oracle, Sybase, Postgres, and SQL Server
use SQL as their standard database language. SQL programming language
uses various commands for different operations.

Why Use SQL?


Here, are important reasons for using SQL

 It helps users to access data in the RDBMS.


 It helps you to describe the data.
 It allows you to define the data in a database and manipulate that
specific data.
 With the help of SQL commands in DBMS, you can create and drop
databases and tables.
 SQL offers you to use the function in a database, create a view, and
stored procedure.
 You can set permissions on tables, procedures, and views.

Types of SQL commands


Here are five types of commands widely used SQL queries.

 Data Definition Language (DDL)


 Data Manipulation Language (DML)
 Data Control Language (DCL)
 Transaction Control Language (TCL)
 Data Query Language (DQL)
Let’s explore the differences between DELETE, DROP, and TRUNCATE in
SQL:
DELETE:
Purpose: DELETE is a Data Manipulation Language (DML) command.
Function: It removes one or more rows from a table.
Usage:
You can delete all rows at once or selectively using a WHERE clause.
Slower than TRUNCATE.
Supports rollback (can be undone).
Syntax:
To delete all rows: DELETE FROM <table_name>;
To delete rows based on a condition: DELETE FROM <table_name> WHERE
<condition>;
DROP:
Purpose: DROP is a Data Definition Language (DDL) command.
Function: It removes the entire table along with its structure (columns,
indexes, constraints, triggers).
Usage:
Irreversible action (cannot be rolled back).
Efficient for removing the entire table.
Syntax:
To drop a table: DROP TABLE <table_name>;
TRUNCATE:
Purpose: TRUNCATE is also a DDL command.
Function: It deletes all rows from a table in one go (without using a
WHERE clause).
Usage:
Faster than DELETE for large tables.
Irreversible action (cannot be rolled back).
Syntax:
To truncate a table: TRUNCATE TABLE <table_name>;
Comparison:

Paramete DELETE DROP TRUNCATE


r
Language DML DDL DDL
Purpose Row removal Table removal Row removal

Rollback Can be Cannot be Cannot be

Efficiency Less efficient Depends on size More efficient

DATA TYPES:
In SQL, data types define the type of data that a column or variable can
hold. Each database system has its own set of data types, some common
ones used across different databases:
String Data Types:
CHAR(size): A fixed-length string (can contain letters, numbers, and
special characters). The size parameter specifies the column length in
characters (0 to 255).
VARCHAR(size): A variable-length string (maximum string length from 0
to 65535 characters).
TEXT(size): Holds a string with a maximum length of 65,535 bytes.
ENUM(val1, val2, val3, …): A string object with a single value chosen
from a list of possible values.
SET(val1, val2, val3, …): A string object that can have zero or more
values from a list of possible values.
Numeric Data Types:
BIT(size): A bit-value type (1 to 64 bits per value).
TINYINT(size): A very small integer (signed range: -128 to 127, unsigned
range: 0 to 255).
INT(size): Integer data type (various sizes).
FLOAT(size, d): Floating-point number (single-precision).
DECIMAL(size, d): Exact numeric data type (fixed-point).
Date and Time Data Types:
DATE: Stores date values (YYYY-MM-DD).
TIME: Stores time values (HH:MM:SS).
DATETIME: Stores both date and time values.
TIMESTAMP: Stores date and time, including fractional seconds.
Binary Data Types:
BINARY(size): Stores binary byte strings (size in bytes).
VARBINARY(size): Stores variable-length binary byte strings.
BLOB(size): For binary large objects (up to 65,535 bytes).
Other Data Types:
BOOLEAN: Represents true or false values.
JSON: Stores JSON data.
GEOMETRY: Stores spatial data (used in GIS applications).
Remember that data types ensure data integrity and efficient storage.
Always check the documentation for specific details and variations in
different databases!

You might also like