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

Fundamentals of SQL: Datonics Club Initiative - Session 1

The document provides an overview of the content to be covered in a session on fundamentals of SQL. The content includes definitions of databases and database models, major SQL data types, SQL queries including SELECT statements and usage of clauses like WHERE, AND, OR and ORDER BY. It also covers topics like primary keys, constraints, different types of SQL joins and SQL functions for strings and numbers.

Uploaded by

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

Fundamentals of SQL: Datonics Club Initiative - Session 1

The document provides an overview of the content to be covered in a session on fundamentals of SQL. The content includes definitions of databases and database models, major SQL data types, SQL queries including SELECT statements and usage of clauses like WHERE, AND, OR and ORDER BY. It also covers topics like primary keys, constraints, different types of SQL joins and SQL functions for strings and numbers.

Uploaded by

Atindra Saha
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Fundamentals of SQL

DATONICS CLUB INITIATIVE – SESSION 1


Session Content

Content

1. Database – Definition
2. Database Models
3. RDBMS
4. Major SQL DataTypes
5. SQL Queries – The Beginning
6. Primary Key and Constraint
7. SELECT, DISTINCT and WHERE Clause
8. Usage of AND OR LIKE and ORDER BY
9. SQL Joins – Full Details
10. SQL String Functions
11. SQL Numeric Functions
Database – The definition

 A Database is simply a digital


register for storing Hierarchical
information.
 Remember!!!!!
 Not all Databases store data in Relational
tabular format
 Databases are of 3 types based
on the organization of data
Network
Databases Model Defined
RDBMS
Major SQL datatypes

String Data Type Numeric Data Type Date and Time

1. CHAR
2. VARCHAR 1. BOOLEAN
3. BINARY 2. INTEGER 1. DATE
4. VARBINARY 3. BIGINT 2. DATETIME
5. TEXT (65535 Bytes) 4. FLOAT 3. TIMESTAMP
6. ENUM(val1, val2, val3…) 5. DOUBLE 4. TIME
7. SET 6. DECIMAL 5. YEAR
SQL Queries – The Beginning

 CREATE DB
 CREATE TABLE
 DROP DB
CREATE TABLE table_na DROP DATABASE db_Name
 DROP TABLE me ( ALTER TABLE table_nam
; e
 ALTER TABLE ADD column_name
    column1 datatype,
datatype;
    column2 datatype,
    column3 datatype, DROP TABLE table_name DROP column_name
   .... ; datatype
);
Primary Key and Constraint

The PRIMARY KEY constraint uniquely identifies each record in a table.


Primary keys must contain UNIQUE values, and cannot contain NULL values.
A table can have only ONE primary key; and in the table, this primary key can consist of single or multiple
columns (fields).

CREATE TABLE Persons (
CREATE TABLE Persons (
    Name varchar(255) NOT NULL,
    ID int NOT NULL,
    LastName varchar(255) NOT NULL,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    FirstName varchar(255),
    Age int,
    Age int,
    CONSTRAINT PK_Person PRIMARY KEY 
    PRIMARY KEY (ID)
(Age,LastName)
);
);
A Simple Query – Select, Distinct and Where
Clause

SELECT CustomerName, SELECT DISTINCT(CustomerName),


Address, Address,
City, City,
Postalcode Postalcode
FROM Customers FROM Customers
WHERE Country='Mexico'; WHERE Country='Mexico';
SQL Query – Usage of AND, OR, LIKE and
Order By

SELECT CustomerName, SELECT CustomerName, SELECT CustomerName,


Address, Address, Address,
City, City, City,
Postalcode Postalcode Postalcode
FROM Customers FROM Customers FROM Customers
WHERE Country WHERE Country WHERE Country
='Mexico' AND ='Mexico' AND ='Mexico’
PostalCode = CustomerName LIKE Order By
‘05021'; 'Ana%'; CustomerName DESC
SQL Joins – INNER and OUTER
SQL Inner Join

SELECT *
FROM Analytics
INNER JOIN Marketing
ON 
Analytics.Roll_Number = 
Marketing.Roll_Number
SQL Left Outer Join/Left Join

SELECT *
FROM Analytics
LEFT
OUTER JOIN Marketing
ON 
Analytics.Roll_Number = 
Marketing.Roll_Number
SQL Right Outer Join/Right Join

SELECT *
FROM Analytics
RIGHT
OUTER JOIN Marketing
ON 
Analytics.Roll_Number = 
Marketing.Roll_Number
SQL Full Outer Join/Full Join

SELECT *
FROM Analytics
FULL JOIN Marketing
ON 
Analytics.Roll_Number = 
Marketing.Roll_Number
SQL String Functions

SELECT LENGTH (‘IIM SELECT TRIM (' SQL


SELECT UPPER (‘sql‘)
SIRMAUR’) Tutorial! ‘)
Ans: SQL
Ans: 11 Ans: SQL Tutorial

SELECT INITCAP (‘IIM SELECT CONCAT (‘SQL’, SELECT SUBSTRING('SQL


SIRMAUR’) ‘Tutorial!‘) Tutorial', 1, 3)
Ans: Iim Sirmaur Ans: SQL Tutorial Ans: SQL
SQL Numeric Functions

SELECT COUNT(ProductID)  SELECT MAX(Price) FROM  SELECT MIN(Price)FROM 


FROM Products Products Products

SELECT SUM(Quantity) SELECT AVG(Price)
SELECT POWER(7, 3);
FROM OrderDetails FROM Products

You might also like