SlideShare a Scribd company logo
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Views, Triggers, Functions- Calling a function, return type,
          Stored Procedures, Indexing and Joins
VIEWS

•    The view is a virtual table. It does not physically exist. Rather, it is created by a
    query joining one or more tables.
•    A view contains rows and columns, just like a real table
•   The fields in a view are fields from one or more real tables in the database

Creating an SQL VIEW
Syntax:
          CREATE VIEW view_name AS
          SELECT column_name(s)
          FROM table_name
          WHERE condition;
View Creation - Example

•   View Creation - Example
    CREATE VIEW sup_orders
    AS SELECT suppliers.supplier_id, orders.quantity, orders.price
    FROM suppliers, orders
    WHERE suppliers.supplier_id = orders.supplier_id and suppliers.supplier_name = 'IBM';

•   This View (Create statement) would create a virtual table based on the result set of the select
    statement. You can now query the view as follows

     SELECT * FROM sup_orders;
Updating VIEW

•   You can modify the definition of a VIEW without dropping it by using the following
    syntax
    CREATE OR REPLACE VIEW view_name
    AS SELECT columns
    FROM table
    WHERE predicates;

•    View Modify - Example
    CREATE or REPLACE VIEW sup_orders
    AS SELECT suppliers.supplier_id, orders.quantity, orders.price
    FROM suppliers, orders
    WHERE suppliers.supplier_id = orders.supplier_id
    and suppliers.supplier_name = 'Microsoft';
Dropping VIEW
•   The syntax for dropping a VIEW :

    DROP VIEW view_name;

•    View Drop - Example

    DROP VIEW sup_orders;

Question: Can you update the data in an view?
Answer : A view is created by joining one or more tables. When you update record(s) in a view, it
   updates the records in the underlying tables that make up the View.
   So, yes, you can update the data in View providing you have the proper privileges to the
   underlying tables.
Question: Does the SQL View exist if the table is dropped from the database?
Answer: Yes, View continues to exist even after one of the tables (that the SQL View is based on) is
   dropped from the database. However, if you try to query the View after the table has been
   dropped, you will receive a message indicating that the View has errors.
TRIGGER
•   What is a Trigger?

     A trigger is a block structure which is fired when a DML statements like Insert,
    Delete, Update is executed on a database table. A trigger is triggered automatically
    when an associated DML statement is executed.
•   Syntax of Triggers

    CREATE [OR REPLACE ] TRIGGER trigger_name
    {BEFORE | AFTER | INSTEAD OF }
    {INSERT [OR] | UPDATE [OR] | DELETE}
    [OF col_name]
    ON table_name
    [REFERENCING OLD AS o NEW AS n]
    [FOR EACH ROW]
    WHEN (condition) ;
TRIGGER


•   The syntax for a dropping a Trigger is:

                      DROP TRIGGER trigger_name ON tbl_name;

•   The syntax for a disabling a Trigger is:

                ALTER TRIGGER trigger_name DISABLE;

•   The syntax for a enabling a Trigger is:

                ALTER TRIGGER trigger_name ENABLE;
Example


•   Creating Trigger

    CREATE TRIGGER deleted_detailss
    BEFORE
    DELETE on tbl_customer
     FOR EACH ROW
    EXECUTE PROCEDURE customerss_delete();

•   Drop Trigger

    drop trigger delete_details on tbl_customer;
Functions

•  A function is a group of statements that executes upon request
•  Python provides many built-in functions and allows programmers to define their own
   functions
• A request to execute a function is known as a function call
• When a function is called, it may be passed arguments that specify data upon which
   the function performs its computation
• Functions defined within class statements are also called methods
The def Statement
• The def statement is the most common way to define a function
Syntax
                           def function-name(parameters):
                                statement(s)
Functions

The return keyword
• A function is created to do a specific task
• Often there is a result from such a task
• The return keyword is used to return values from a function
• A function may or may not return a value
• If a function does not have a return keyword, it will send a None value
Example
def showMessage(msg):
  print msg

def cube(x):
  return x * x * x
def main():
  x = cube(3)
  print x
  showMessage("Computation finished.")
  print showMessage("Ready.")
main()

output:
baabtra@baabtra-desktop:~$ python ppt.py
27
Computation finished.
Ready.
None
Calling Functions

•   A function call is an expression with the following syntax:
               function-object(arguments)
•    function-object It is most often the function's name.
•   The parentheses denote the function-call operation itself.
•   Arguments, in the simplest case, is a series of zero or more expressions separated by
    commas (,), giving values for the function's corresponding formal parameters
Calling Functions

total = 0;
# Function definition is here
def sum( arg1, arg2 ):
  # Add both the parameters and return them."
  total = arg1 + arg2;
  # Here total is local variable.
  print "Inside the function local total : ", total
  return total;

def main():
# Now you can call sum function
 sum( 10, 20 );
 print "Outside the function global total : ", total
main()


output:
baabtra@baabtra-desktop:~$ python ppt2.py
Inside the function local total : 30
Outside the function global total : 0
Advantage

The advantages of using functions are:
• Reducing duplication of code
• Improving clarity of the code
• Reuse of code
• Information hiding
INDEX

•   The CREATE INDEX statement is used to create indexes in tables

•   Indexes allow the database application to find data fast; without reading the whole
    table

•   An index can be created in a table to find data more quickly and efficiently

•   The users cannot see the indexes, they are just used to speed up searches/queries
INDEX

•   CREATE INDEX Syntax
    Creates an index on a table. Duplicate values are allowed:

    CREATE INDEX index_name
    ON table_name (column_name);

•   CREATE UNIQUE INDEX Syntax
    Creates a unique index on a table. Duplicate values are not allowed:

    CREATE UNIQUE INDEX index_name
    ON table_name (column_name);

•   UNIQUE indicates that the combination of values in the indexed columns must be
    unique
INDEX


•   Rename an Index
    The syntax for renaming an index is:

    ALTER INDEX index_name RENAME TO new_index_name;



•   Drop an Index
    The syntax for dropping an index is:



    DROP INDEX index_name;
JOINS
•   Joins are used to query data from two or more tables, based on a relationship
    between certain columns in these tables

•   Types of Joins

    LEFT JOIN: Return all rows from the left table, even if there are no matches in the
    right table
    RIGHT JOIN: Return all rows from the right table, even if there are no matches in
    the left table
    FULL JOIN: Return rows when there is a match in one of the tables
INNER JOIN
•   The INNER JOIN keyword returns rows when there is at least one match in both
    tables

•    INNER JOIN Syntax
    SELECT column_name(s)
     FROM table_name1
     INNER JOIN table_name2
     ON table_name1.column_name=table_name2.column_name;

•    If there are rows in “table_name1 " that do not have matches in " table_name2 ",
    those rows will NOT be listed
LEFT JOIN

•   The LEFT JOIN keyword returns all rows from the left table (table_name1), even if
    ther are no matches in the right table (table_name2)

•    LEFT JOIN Syntax
    SELECT column_name(s)
     FROM table_name1
     LEFT JOIN table_name2
     ON table_name1.column_name=table_name2.column_name;
RIGHT JOIN
•   The RIGHT JOIN keyword returns all the rows from the right table (table_name2),
    even if there are no matches in the left table (table_name1)

•   RIGHT JOIN Syntax
    SELECT column_name(s)
    FROM table_name1
    RIGHT JOIN table_name2
    ON table_name1.column_name=table_name2.column_name;
FULL JOIN

•   The FULL JOIN keyword return rows when there is a match in one of the tables

FULL JOIN Syntax
   SELECT column_name(s)
   FROM table_name1
   FULL JOIN table_name2
   ON table_name1.column_name=table_name2.column_name;

•   The FULL JOIN keyword returns all the rows from the left table (Table1), and all the rows
    from the right table (Table2). If there are rows in " Table1 " that do not have matches in "
    Table2", or if there are rows in " Table2" that do not have matches in " Table1 ", those rows
    will be listed as well.
stored procedure

•   In a database management system (DBMS), a stored procedure is a set of Structured Query
    Language (SQL) statements with an assigned name that's stored in the database in compiled
    form so that it can be shared by a number of programs.

•   preserving data integrity (information is entered in a consistent manner)

    Data integrity means the correctness and consistency of data
    Enforcing data integrity ensures the quality of the data in the database
    Consider following two examples of data integriry in a database

    1) If an employee is entered with an employee_id value of 123, the database should not allow
    another employee to have an ID with the same value

    2) If you have an employee_rating column intended to have values ranging from 1 to 5, the
    database should not accept a value of 6
Example

CREATE OR REPLACE FUNCTION insert_tbl_customer(int,text,date,text,int,boolean)
RETURNS void AS
$delimiter$
INSERT INTO tbl_customer (pk_int_cu_id, vchr_cname, dat_dob, vchr_email,bint_phone,bln_sex)
VALUES ($1,$2,$3,$4,$5,$6);
$delimiter$
LANGUAGE SQL;

select insert_tbl_customer(201,'john','1990-10-5','b@gmail',94,true);
If this presentation helped you, please visit our page
               facebook.com/baabtra and like it.
                  Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us

More Related Content

What's hot

SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
Naimul Arif
 
SQL commands
SQL commandsSQL commands
SQL commands
GirdharRatne
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
Sql join
Sql  joinSql  join
Sql join
Vikas Gupta
 
Triggers
TriggersTriggers
Triggers
Pooja Dixit
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Sql joins
Sql joinsSql joins
Sql joins
Gaurav Dhanwant
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
Raveena Thakur
 
SQL Views
SQL ViewsSQL Views
SQL Views
Aaron Buma
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
 
SQL
SQLSQL
SQL Basics
SQL BasicsSQL Basics
SQL Basics
Hammad Rasheed
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
Aliya Saldanha
 

What's hot (20)

Trigger
TriggerTrigger
Trigger
 
SQL Join Basic
SQL Join BasicSQL Join Basic
SQL Join Basic
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
Sql join
Sql  joinSql  join
Sql join
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Triggers
TriggersTriggers
Triggers
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Sql joins
Sql joinsSql joins
Sql joins
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
SQL
SQLSQL
SQL
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
 
Sql select
Sql select Sql select
Sql select
 

Similar to SQL Views

SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
Java class 8
Java class 8Java class 8
Java class 8Edureka!
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Md. Mahedee Hasan
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objects
Syed Zaid Irshad
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
YashaswiniSrinivasan1
 
Module 3
Module 3Module 3
Module 3
cs19club
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
Database Overview
Database OverviewDatabase Overview
Database Overview
Livares Technologies Pvt Ltd
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
DraguClaudiu
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)
PadmapriyaA6
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 

Similar to SQL Views (20)

Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Java class 8
Java class 8Java class 8
Java class 8
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objects
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Module 3
Module 3Module 3
Module 3
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
Database Overview
Database OverviewDatabase Overview
Database Overview
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
 
Structured Query Language(SQL)
Structured Query Language(SQL)Structured Query Language(SQL)
Structured Query Language(SQL)
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 

More from baabtra.com - No. 1 supplier of quality freshers

Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Php database connectivity
Php database connectivityPhp database connectivity
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Blue brain
Blue brainBlue brain
5g
5g5g
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 

SQL Views

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Views, Triggers, Functions- Calling a function, return type, Stored Procedures, Indexing and Joins
  • 4. VIEWS • The view is a virtual table. It does not physically exist. Rather, it is created by a query joining one or more tables. • A view contains rows and columns, just like a real table • The fields in a view are fields from one or more real tables in the database Creating an SQL VIEW Syntax: CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition;
  • 5. View Creation - Example • View Creation - Example CREATE VIEW sup_orders AS SELECT suppliers.supplier_id, orders.quantity, orders.price FROM suppliers, orders WHERE suppliers.supplier_id = orders.supplier_id and suppliers.supplier_name = 'IBM'; • This View (Create statement) would create a virtual table based on the result set of the select statement. You can now query the view as follows SELECT * FROM sup_orders;
  • 6. Updating VIEW • You can modify the definition of a VIEW without dropping it by using the following syntax CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table WHERE predicates; • View Modify - Example CREATE or REPLACE VIEW sup_orders AS SELECT suppliers.supplier_id, orders.quantity, orders.price FROM suppliers, orders WHERE suppliers.supplier_id = orders.supplier_id and suppliers.supplier_name = 'Microsoft';
  • 7. Dropping VIEW • The syntax for dropping a VIEW : DROP VIEW view_name; • View Drop - Example DROP VIEW sup_orders; Question: Can you update the data in an view? Answer : A view is created by joining one or more tables. When you update record(s) in a view, it updates the records in the underlying tables that make up the View. So, yes, you can update the data in View providing you have the proper privileges to the underlying tables. Question: Does the SQL View exist if the table is dropped from the database? Answer: Yes, View continues to exist even after one of the tables (that the SQL View is based on) is dropped from the database. However, if you try to query the View after the table has been dropped, you will receive a message indicating that the View has errors.
  • 8. TRIGGER • What is a Trigger? A trigger is a block structure which is fired when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is triggered automatically when an associated DML statement is executed. • Syntax of Triggers CREATE [OR REPLACE ] TRIGGER trigger_name {BEFORE | AFTER | INSTEAD OF } {INSERT [OR] | UPDATE [OR] | DELETE} [OF col_name] ON table_name [REFERENCING OLD AS o NEW AS n] [FOR EACH ROW] WHEN (condition) ;
  • 9. TRIGGER • The syntax for a dropping a Trigger is: DROP TRIGGER trigger_name ON tbl_name; • The syntax for a disabling a Trigger is: ALTER TRIGGER trigger_name DISABLE; • The syntax for a enabling a Trigger is: ALTER TRIGGER trigger_name ENABLE;
  • 10. Example • Creating Trigger CREATE TRIGGER deleted_detailss BEFORE DELETE on tbl_customer FOR EACH ROW EXECUTE PROCEDURE customerss_delete(); • Drop Trigger drop trigger delete_details on tbl_customer;
  • 11. Functions • A function is a group of statements that executes upon request • Python provides many built-in functions and allows programmers to define their own functions • A request to execute a function is known as a function call • When a function is called, it may be passed arguments that specify data upon which the function performs its computation • Functions defined within class statements are also called methods The def Statement • The def statement is the most common way to define a function Syntax def function-name(parameters): statement(s)
  • 12. Functions The return keyword • A function is created to do a specific task • Often there is a result from such a task • The return keyword is used to return values from a function • A function may or may not return a value • If a function does not have a return keyword, it will send a None value
  • 13. Example def showMessage(msg): print msg def cube(x): return x * x * x def main(): x = cube(3) print x showMessage("Computation finished.") print showMessage("Ready.") main() output: baabtra@baabtra-desktop:~$ python ppt.py 27 Computation finished. Ready. None
  • 14. Calling Functions • A function call is an expression with the following syntax: function-object(arguments) • function-object It is most often the function's name. • The parentheses denote the function-call operation itself. • Arguments, in the simplest case, is a series of zero or more expressions separated by commas (,), giving values for the function's corresponding formal parameters
  • 15. Calling Functions total = 0; # Function definition is here def sum( arg1, arg2 ): # Add both the parameters and return them." total = arg1 + arg2; # Here total is local variable. print "Inside the function local total : ", total return total; def main(): # Now you can call sum function sum( 10, 20 ); print "Outside the function global total : ", total main() output: baabtra@baabtra-desktop:~$ python ppt2.py Inside the function local total : 30 Outside the function global total : 0
  • 16. Advantage The advantages of using functions are: • Reducing duplication of code • Improving clarity of the code • Reuse of code • Information hiding
  • 17. INDEX • The CREATE INDEX statement is used to create indexes in tables • Indexes allow the database application to find data fast; without reading the whole table • An index can be created in a table to find data more quickly and efficiently • The users cannot see the indexes, they are just used to speed up searches/queries
  • 18. INDEX • CREATE INDEX Syntax Creates an index on a table. Duplicate values are allowed: CREATE INDEX index_name ON table_name (column_name); • CREATE UNIQUE INDEX Syntax Creates a unique index on a table. Duplicate values are not allowed: CREATE UNIQUE INDEX index_name ON table_name (column_name); • UNIQUE indicates that the combination of values in the indexed columns must be unique
  • 19. INDEX • Rename an Index The syntax for renaming an index is: ALTER INDEX index_name RENAME TO new_index_name; • Drop an Index The syntax for dropping an index is: DROP INDEX index_name;
  • 20. JOINS • Joins are used to query data from two or more tables, based on a relationship between certain columns in these tables • Types of Joins LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table FULL JOIN: Return rows when there is a match in one of the tables
  • 21. INNER JOIN • The INNER JOIN keyword returns rows when there is at least one match in both tables • INNER JOIN Syntax SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name; • If there are rows in “table_name1 " that do not have matches in " table_name2 ", those rows will NOT be listed
  • 22. LEFT JOIN • The LEFT JOIN keyword returns all rows from the left table (table_name1), even if ther are no matches in the right table (table_name2) • LEFT JOIN Syntax SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name=table_name2.column_name;
  • 23. RIGHT JOIN • The RIGHT JOIN keyword returns all the rows from the right table (table_name2), even if there are no matches in the left table (table_name1) • RIGHT JOIN Syntax SELECT column_name(s) FROM table_name1 RIGHT JOIN table_name2 ON table_name1.column_name=table_name2.column_name;
  • 24. FULL JOIN • The FULL JOIN keyword return rows when there is a match in one of the tables FULL JOIN Syntax SELECT column_name(s) FROM table_name1 FULL JOIN table_name2 ON table_name1.column_name=table_name2.column_name; • The FULL JOIN keyword returns all the rows from the left table (Table1), and all the rows from the right table (Table2). If there are rows in " Table1 " that do not have matches in " Table2", or if there are rows in " Table2" that do not have matches in " Table1 ", those rows will be listed as well.
  • 25. stored procedure • In a database management system (DBMS), a stored procedure is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. • preserving data integrity (information is entered in a consistent manner) Data integrity means the correctness and consistency of data Enforcing data integrity ensures the quality of the data in the database Consider following two examples of data integriry in a database 1) If an employee is entered with an employee_id value of 123, the database should not allow another employee to have an ID with the same value 2) If you have an employee_rating column intended to have values ranging from 1 to 5, the database should not accept a value of 6
  • 26. Example CREATE OR REPLACE FUNCTION insert_tbl_customer(int,text,date,text,int,boolean) RETURNS void AS $delimiter$ INSERT INTO tbl_customer (pk_int_cu_id, vchr_cname, dat_dob, vchr_email,bint_phone,bln_sex) VALUES ($1,$2,$3,$4,$5,$6); $delimiter$ LANGUAGE SQL; select insert_tbl_customer(201,'john','1990-10-5','b@gmail',94,true);
  • 27. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com