SlideShare a Scribd company logo
Database Architecture and Basic
          Concepts
            What is Database?
       Structured Query Language
           Stored Procedures
What is Database?
 A database is an object for storing complex, structured
  information.
 What make database unique is the fact that databases are
  design to retrieve data quickly.
 Database samples such as Access and SQL Server called
  database management systems (DBMS).
 To access the data stored in the database and to update the
  database, you use a special language, Structure Query
  Language (SQL).
Continue…
 Relational Databases
Continue…
Structure Query Language
 SQL (Structured Query Language) is a universal language for
  manipulating tables, and every database management system
  (DBMS) supports it.

 SQL is a nonprocedural language.


 SQL statements are categorized into two major categories:
   Data Manipulation Language (DML)
   Data Definition Language (DDL)
Continue…
 Executing SQL Statements.
   Opening Microsoft SQL Server Management Studio
   Using New Query Windows.
Continue…
 Selection Queries
   The simplest form of the SELECT statement is


   SELECT fields
   FROM tables

   where fields and tables are comma-separated lists of the fields you want
   to retrieve from the database
   and the tables they belong to.
 WHERE Clause
  To restrict the rows returned by the query, use the WHERE clause
  of the SELECT statement. The most common form of the SELECT statement is
     the following:
  SELECT fields
  FROM tables
  WHERE condition
  The fields and tables arguments are the same as before.

 Sample:
 SELECT ProductName, CategoryName
 FROM Products
 WHERE CategoryID In (2, 5,6,10)
 TOP Keyword
   Some queries may retrieve a large number of rows, while
    you‟re interested in the top few rows only.
   The TOP N keyword allows you to select the first N rows and
    ignore the remaining ones.
 DISTINCT Keyword
   The DISTINCT keyword eliminates any duplicates from the
    cursor retrieved by the SELECT statement.
 SELECT DISTINCT Country
 FROM Customers
 ORDER Keyword
   The rows of a query are not in any particular order. To request
    that the rows be returned in a specific order, use the
    ORDER BY clause, whose syntax is
           ORDER BY col1, col2, . . .

            SELECT CompanyName, ContactName
                    FROM Customers
                 ORDER BY Country, City
 SQL Join
   Joins specify how you connect multiple tables in a query, and there are four types
      of joins:
           Left outer, or left join
           Right outer, or right join
           Full outer, or full join
           Inner join


    Left Joins
      This join displays all the records in the left table and only those records of the
      table on the right that match certain user-supplied criteria. This join has the
      following syntax:
      FROM (primary table) LEFT JOIN (secondary table) ON (primary table).(field)
      (comparison) (secondary table).(field)
          SELECT title, pub_name
          FROM titles LEFT JOIN publishers
          ON titles.pub_id = publishers.pub_id
 Right Joins
  This join is similar to the left outer join, except that all rows in the table on the right
  are displayed and only the matching rows from the left table are displayed. This join has
  the following syntax:
  FROM (secondary table) RIGHT JOIN (primary table) ON (secondary table).(field)
  (comparison) (primary table).(field)

  “SELECT title, pub_name
  FROM titles RIGHT JOIN publishers
  ON titles.pub_id = publishers.pub_id”

 Full Joins
  The full join returns all the rows of the two tables, regardless of whether there are
  matching rows or not. In effect, it‟s a combination of left and right joins.

   “SELECT title, pub_name
   FROM titles FULL JOIN publishers
   ON titles.pub_id = publishers.pub_id”
 Inner Joins
  This join returns the matching rows of both tables, similar to the WHERE clause, and has
  the following syntax:
  FROM (primary table) INNER JOIN (secondary table) ON (primary table).(field)
  (comparison) (secondary table).(field)

“SELECT titles.title, publishers.pub_name FROM titles, publishers
              WHERE titles.pub_id = publishers.pub_id”

                                        Or

                “SELECT titles.title, publishers.pub_name
    FROM titles INNER JOIN publishers ON titles.pub_id =
                    publishers.pub_id”
 Grouping Rows
  Sometimes you need to group the results of a query, so that you
   can calculate subtotals.
      SELECT ProductID,
           SUM(Quantity * UnitPrice *(1 - Discount))
           AS [Total Revenues]
      FROM [Order Details]
      GROUP BY ProductID
      ORDER BY ProductID
 Action Queries
   Execute queries that alter the data in the database‟s tables.
   There are three types of actions you can perform against a database:
    1.   Insertions of new rows (INSERT)
    2.   Deletions of existing rows (DELETE)
    3.   Updates (edits) of existing rows (UPDATE)

   Deleting Rows
        The DELETE statement deletes one or more rows
        from a table, and its syntax is:
        DELETE table_name WHERE criteria

                                 “DELETE Orders
                           WHERE OrderDate < „1/1/1998‟ ”
 Inserting New Rows
      The syntax of the INSERT statement is:

      INSERT table_name (column_names) VALUES (values)

  column_names and values are comma-separated lists of columns and their respective values.

“INSERT Customers (CustomerID, CompanyName) VALUES („FRYOG‟, „Fruit &
                                Yogurt‟)”

                                           Or

                     “INSERT INTO SelectedProducts
        SELECT * FROM Products WHERE CategoryID = 4”
 Editing Existing Rows
 The UPDATE statement edits a row‟s fields, and its syntax is

 UPDATE table_name SET field1 = value1, field2 = value2,
 … WHERE criteria

   “UPDATE Customers SET Country=‟United Kingdom‟
              WHERE Country = „UK‟ “
SQL SUMMARY
EXECUTED STATEMENT
Client/server architecture
Stored Procedures
 Stored procedures are short programs that are executed on the server and
  perform very specific tasks.
 Any action you perform against the database frequently should be coded
  as a stored procedure, so that you can call it from within any application
  or from different parts of the same application.
 Benefit:
    Stored procedures isolate programmers from the database and minimize the
     risk of impairing the database‟s integrity.
    You don‟t risk implementing the same operation in two different ways.
    Using stored procedures is that they‟re compiled by SQL Server and they‟re
     executed faster.
    Stored procedures contain traditional programming statements that allow
     you to validate arguments, use default argument values, and so on.
 The language you use to write stored procedure is called T-SQL, and it‟s
  a superset of SQL.
ALTER PROCEDURE dbo.SalesByCategory
   @CategoryName nvarchar(15),
   @OrdYear nvarchar(4) = „1998‟
AS
IF @OrdYear != „1996‟ AND @OrdYear != „1997‟ AND @OrdYear != „1998‟
BEGIN
   SELECT @OrdYear = „1998‟
END
SELECT ProductName,
   TotalPurchase = ROUND(SUM(CONVERT(decimal(14,2),
   OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0)
FROM [Order Details] OD, Orders O, Products P, Categories C
WHERE OD.OrderID = O.OrderID
   AND OD.ProductID = P.ProductID
   AND P.CategoryID = C.CategoryID
   AND C.CategoryName = @CategoryName
   AND SUBSTRING(CONVERT(nvarchar(22), O.OrderDate, 111), 1, 4) = @OrdYear
GROUP BY ProductName
ORDER BY ProductName

More Related Content

What's hot (20)

PPTX
SQL Commands
Sachidananda M H
 
PDF
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
PDF
SQL Overview
Stewart Rogers
 
PPTX
Basic SQL and History
SomeshwarMoholkar
 
PPTX
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
PPT
SQL Tutorial - Basic Commands
1keydata
 
PPTX
Vistas en mySql
Eduardo Ed
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPTX
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Physical database design(database)
welcometofacebook
 
PPT
Mysql
TSUBHASHRI
 
PPT
Database performance tuning and query optimization
Usman Tariq
 
PPTX
SQL Basics
Hammad Rasheed
 
PPTX
Sql Basics And Advanced
rainynovember12
 
PPT
Data dictionary
Surbhi Panhalkar
 
PPTX
An Introduction To Oracle Database
Meysam Javadi
 
PDF
Oracle User Management
Arun Sharma
 
PPTX
Oracle Database View
Eryk Budi Pratama
 
PDF
SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
SQL Commands
Sachidananda M H
 
Chapter 4 Structured Query Language
Eddyzulham Mahluzydde
 
SQL Overview
Stewart Rogers
 
Basic SQL and History
SomeshwarMoholkar
 
Basic sql Commands
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
SQL Tutorial - Basic Commands
1keydata
 
Vistas en mySql
Eduardo Ed
 
introdution to SQL and SQL functions
farwa waqar
 
Physical database design(database)
welcometofacebook
 
Mysql
TSUBHASHRI
 
Database performance tuning and query optimization
Usman Tariq
 
SQL Basics
Hammad Rasheed
 
Sql Basics And Advanced
rainynovember12
 
Data dictionary
Surbhi Panhalkar
 
An Introduction To Oracle Database
Meysam Javadi
 
Oracle User Management
Arun Sharma
 
Oracle Database View
Eryk Budi Pratama
 
SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 

Viewers also liked (20)

PDF
Database system architecture
Dk Rukshan
 
PPTX
Dbms architecture
Shubham Dwivedi
 
PPTX
Database System Architectures
Information Technology
 
PPS
Architecture of-dbms-and-data-independence
Anuj Modi
 
PDF
DBMS Architectures and Features - Lecture 7 - Introduction to Databases (1007...
Beat Signer
 
PPT
Data independence
Aashima Wadhwa
 
PPT
Database system concepts
Kumar
 
PPTX
Dbms slides
rahulrathore725
 
PDF
Dbms
Nitesh Nayal
 
PPT
Basic DBMS ppt
dangwalrajendra888
 
PPT
Database management system presentation
sameerraaj
 
PDF
Database and Java Database Connectivity
Gary Yeh
 
PDF
Database System Concepts and Architecture
sontumax
 
PPT
Bsc cs ii-dbms- u-ii-database system concepts and architecture
Rai University
 
PPTX
Slide 3 data abstraction & 3 schema
Visakh V
 
PPT
A N S I S P A R C Architecture
Sabeeh Ahmed
 
PPT
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
Vikas Jagtap
 
PPTX
physical and logical data independence
apoorva_upadhyay
 
PPT
Types dbms
Avnish Shaw
 
PPTX
Data base management system
Navneet Jingar
 
Database system architecture
Dk Rukshan
 
Dbms architecture
Shubham Dwivedi
 
Database System Architectures
Information Technology
 
Architecture of-dbms-and-data-independence
Anuj Modi
 
DBMS Architectures and Features - Lecture 7 - Introduction to Databases (1007...
Beat Signer
 
Data independence
Aashima Wadhwa
 
Database system concepts
Kumar
 
Dbms slides
rahulrathore725
 
Basic DBMS ppt
dangwalrajendra888
 
Database management system presentation
sameerraaj
 
Database and Java Database Connectivity
Gary Yeh
 
Database System Concepts and Architecture
sontumax
 
Bsc cs ii-dbms- u-ii-database system concepts and architecture
Rai University
 
Slide 3 data abstraction & 3 schema
Visakh V
 
A N S I S P A R C Architecture
Sabeeh Ahmed
 
ADVANCE DATABASE MANAGEMENT SYSTEM CONCEPTS & ARCHITECTURE by vikas jagtap
Vikas Jagtap
 
physical and logical data independence
apoorva_upadhyay
 
Types dbms
Avnish Shaw
 
Data base management system
Navneet Jingar
 
Ad

Similar to Database Architecture and Basic Concepts (20)

PDF
Structure query language, database course
yunussufyan2024
 
PPTX
SQL Server Learning Drive
TechandMate
 
PPT
Ms sql server ii
Iblesoft
 
PPT
SQL.ppt
Ranjit273515
 
PPTX
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
PDF
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
PPTX
SQLSERVERQUERIES.pptx
ssuser6bf2d1
 
PPTX
Introduction to sql new
SANTOSH RATH
 
PPTX
SQL Query
Imam340267
 
PPTX
SQl data base management and design
franckelsania20
 
PPTX
Sql basics
Genesis Omo
 
PPT
chapter 8 SQL.ppt
YitbarekMurche
 
PPTX
Hira
hira elahi
 
PPT
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
PPTX
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
Abhishek590097
 
PPTX
Introduction to database and sql fir beginers
reshmi30
 
DOCX
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
DOCX
Query
Raj Devaraj
 
PPTX
Creating database using sql commands
Belle Wx
 
PPTX
Lab
neelam_rawat
 
Structure query language, database course
yunussufyan2024
 
SQL Server Learning Drive
TechandMate
 
Ms sql server ii
Iblesoft
 
SQL.ppt
Ranjit273515
 
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
SQLSERVERQUERIES.pptx
ssuser6bf2d1
 
Introduction to sql new
SANTOSH RATH
 
SQL Query
Imam340267
 
SQl data base management and design
franckelsania20
 
Sql basics
Genesis Omo
 
chapter 8 SQL.ppt
YitbarekMurche
 
INTRODUCTION TO SQL QUERIES REALTED BRIEF
VADAPALLYPRAVEENKUMA1
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
Abhishek590097
 
Introduction to database and sql fir beginers
reshmi30
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
Creating database using sql commands
Belle Wx
 
Ad

Recently uploaded (20)

PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Geographical diversity of India short notes by sandeep swamy
Sandeep Swamy
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Controller Request and Response in Odoo18
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 

Database Architecture and Basic Concepts

  • 1. Database Architecture and Basic Concepts What is Database? Structured Query Language Stored Procedures
  • 2. What is Database?  A database is an object for storing complex, structured information.  What make database unique is the fact that databases are design to retrieve data quickly.  Database samples such as Access and SQL Server called database management systems (DBMS).  To access the data stored in the database and to update the database, you use a special language, Structure Query Language (SQL).
  • 5. Structure Query Language  SQL (Structured Query Language) is a universal language for manipulating tables, and every database management system (DBMS) supports it.  SQL is a nonprocedural language.  SQL statements are categorized into two major categories:  Data Manipulation Language (DML)  Data Definition Language (DDL)
  • 6. Continue…  Executing SQL Statements.  Opening Microsoft SQL Server Management Studio  Using New Query Windows.
  • 7. Continue…  Selection Queries  The simplest form of the SELECT statement is SELECT fields FROM tables where fields and tables are comma-separated lists of the fields you want to retrieve from the database and the tables they belong to.
  • 8.  WHERE Clause To restrict the rows returned by the query, use the WHERE clause of the SELECT statement. The most common form of the SELECT statement is the following: SELECT fields FROM tables WHERE condition The fields and tables arguments are the same as before. Sample: SELECT ProductName, CategoryName FROM Products WHERE CategoryID In (2, 5,6,10)
  • 9.  TOP Keyword  Some queries may retrieve a large number of rows, while you‟re interested in the top few rows only.  The TOP N keyword allows you to select the first N rows and ignore the remaining ones.  DISTINCT Keyword  The DISTINCT keyword eliminates any duplicates from the cursor retrieved by the SELECT statement. SELECT DISTINCT Country FROM Customers
  • 10.  ORDER Keyword  The rows of a query are not in any particular order. To request that the rows be returned in a specific order, use the ORDER BY clause, whose syntax is ORDER BY col1, col2, . . . SELECT CompanyName, ContactName FROM Customers ORDER BY Country, City
  • 11.  SQL Join  Joins specify how you connect multiple tables in a query, and there are four types of joins:  Left outer, or left join  Right outer, or right join  Full outer, or full join  Inner join  Left Joins This join displays all the records in the left table and only those records of the table on the right that match certain user-supplied criteria. This join has the following syntax: FROM (primary table) LEFT JOIN (secondary table) ON (primary table).(field) (comparison) (secondary table).(field) SELECT title, pub_name FROM titles LEFT JOIN publishers ON titles.pub_id = publishers.pub_id
  • 12.  Right Joins This join is similar to the left outer join, except that all rows in the table on the right are displayed and only the matching rows from the left table are displayed. This join has the following syntax: FROM (secondary table) RIGHT JOIN (primary table) ON (secondary table).(field) (comparison) (primary table).(field) “SELECT title, pub_name FROM titles RIGHT JOIN publishers ON titles.pub_id = publishers.pub_id”  Full Joins The full join returns all the rows of the two tables, regardless of whether there are matching rows or not. In effect, it‟s a combination of left and right joins. “SELECT title, pub_name FROM titles FULL JOIN publishers ON titles.pub_id = publishers.pub_id”
  • 13.  Inner Joins This join returns the matching rows of both tables, similar to the WHERE clause, and has the following syntax: FROM (primary table) INNER JOIN (secondary table) ON (primary table).(field) (comparison) (secondary table).(field) “SELECT titles.title, publishers.pub_name FROM titles, publishers WHERE titles.pub_id = publishers.pub_id” Or “SELECT titles.title, publishers.pub_name FROM titles INNER JOIN publishers ON titles.pub_id = publishers.pub_id”
  • 14.  Grouping Rows  Sometimes you need to group the results of a query, so that you can calculate subtotals. SELECT ProductID, SUM(Quantity * UnitPrice *(1 - Discount)) AS [Total Revenues] FROM [Order Details] GROUP BY ProductID ORDER BY ProductID
  • 15.  Action Queries  Execute queries that alter the data in the database‟s tables.  There are three types of actions you can perform against a database: 1. Insertions of new rows (INSERT) 2. Deletions of existing rows (DELETE) 3. Updates (edits) of existing rows (UPDATE)  Deleting Rows The DELETE statement deletes one or more rows from a table, and its syntax is: DELETE table_name WHERE criteria “DELETE Orders WHERE OrderDate < „1/1/1998‟ ”
  • 16.  Inserting New Rows The syntax of the INSERT statement is: INSERT table_name (column_names) VALUES (values) column_names and values are comma-separated lists of columns and their respective values. “INSERT Customers (CustomerID, CompanyName) VALUES („FRYOG‟, „Fruit & Yogurt‟)” Or “INSERT INTO SelectedProducts SELECT * FROM Products WHERE CategoryID = 4”
  • 17.  Editing Existing Rows The UPDATE statement edits a row‟s fields, and its syntax is UPDATE table_name SET field1 = value1, field2 = value2, … WHERE criteria “UPDATE Customers SET Country=‟United Kingdom‟ WHERE Country = „UK‟ “
  • 20. Stored Procedures  Stored procedures are short programs that are executed on the server and perform very specific tasks.  Any action you perform against the database frequently should be coded as a stored procedure, so that you can call it from within any application or from different parts of the same application.  Benefit:  Stored procedures isolate programmers from the database and minimize the risk of impairing the database‟s integrity.  You don‟t risk implementing the same operation in two different ways.  Using stored procedures is that they‟re compiled by SQL Server and they‟re executed faster.  Stored procedures contain traditional programming statements that allow you to validate arguments, use default argument values, and so on.  The language you use to write stored procedure is called T-SQL, and it‟s a superset of SQL.
  • 21. ALTER PROCEDURE dbo.SalesByCategory @CategoryName nvarchar(15), @OrdYear nvarchar(4) = „1998‟ AS IF @OrdYear != „1996‟ AND @OrdYear != „1997‟ AND @OrdYear != „1998‟ BEGIN SELECT @OrdYear = „1998‟ END SELECT ProductName, TotalPurchase = ROUND(SUM(CONVERT(decimal(14,2), OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0) FROM [Order Details] OD, Orders O, Products P, Categories C WHERE OD.OrderID = O.OrderID AND OD.ProductID = P.ProductID AND P.CategoryID = C.CategoryID AND C.CategoryName = @CategoryName AND SUBSTRING(CONVERT(nvarchar(22), O.OrderDate, 111), 1, 4) = @OrdYear GROUP BY ProductName ORDER BY ProductName