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

SQL Basics

All basics of sql

Uploaded by

sanikaayare79
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL Basics

All basics of sql

Uploaded by

sanikaayare79
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SQL

SQL (Structured Query Language) is a standardized programming language


used for managing and manipulating databases. It enables users to interact
with databases to perform tasks such as:

▪ Retrieving data
▪ Inserting data
▪ Updating data
▪ Deleting data
▪ Creating and modifying database structures
▪ Managing permissions
Database
• A Database is defined as a structured form of data storage in a computer
or a collection of data in an organized manner and can be accessed in various
ways.
• It is also the collection of schemas, tables, queries, views, etc.

• The Database Management System allows a user to interact with the database.

Relational databases NoSQL databases Cloud-based databases


structured data unstructured or semi-structured structured, unstructured or
data semi-structured data
E.g.: MySQL, PostgreSQL, Oracle E.g.: MongoDB, Cassandra, Redis E.g.: BigQuery, Snowflake, Aurora
Relational Database
A relational database is a type of database that stores and organizes data in
structured tables, which consist of rows and columns. Each table in a relational
database represents an entity (such as customers, products, or orders), and
relationships can be defined between these tables.

Example: A table named Customers might have columns such as


Customer_code, Name, market.
Most Commonly Used Data Types
Numeric Data Types
▪ INT: Stores whole numbers, both positive and negative
E.g.- INT, SMALLINT, TINYINT, BIGINT

▪ DECIMAL(p,s): Used for precise numbers with decimal points where p (Precision) is the
total number of significant digits that can be stored, both to the left and right of the decimal
point and s (Scale) is the number of digits that can be stored to the right of the decimal
point.

E.g.-DECIMAL(5, 2) This can store numbers up to 129.29. The precision is 5 (total digits),
and the scale is 2 (digits after the decimal)

▪ FLOAT: Used for approximate values with floating points.


String Data Types

▪ CHAR(n): Fixed-length string. If the input is shorter than n, it’s padded with spaces.
E.g. – name CHAR(10)
Kanchan - 3 characters are space padding
Kavya - 5 characters are space padding

▪ VARCHAR(n): Variable-length string. Stores only the characters entered, up to n.

▪ TEXT: Holds large amounts of text data.


Date & Time Data Types
▪ DATE: Stores dates (year, month, day) in 'YYYY-MM-DD' format.

▪ TIME: Stores time (hours, minutes, seconds).

▪ DATETIME: Stores date and time together.

▪ TIMESTAMP: Stores date and time based on UTC.

▪ YEAR: Stores a year in two or four digits.


Boolean Data Types
▪ BOOLEAN: Represents true or false values. In most databases, it's stored as TINYINT
(1 for true, 0 for false).

Other Data Types


▪ ENUM: Used to define a list of allowed values, and the field can only contain one of
those values.

E.g. - The order status of any product can be one of the following: shipped,
delivered, cancelled, or pending. If you try to insert any other value into the order
status, it will throw an error.

You might also like