0% found this document useful (0 votes)
55 views2 pages

What Is A in Exists

The document discusses the EXISTS operator in SQL, which returns true if a subquery returns one or more records. It provides an example of using EXISTS to return suppliers with products priced under $20. It also defines stored procedures as reusable SQL code that can be saved and have parameters passed to them, and gives a sample stored procedure to select all customers.

Uploaded by

Payal Mohanty
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)
55 views2 pages

What Is A in Exists

The document discusses the EXISTS operator in SQL, which returns true if a subquery returns one or more records. It provides an example of using EXISTS to return suppliers with products priced under $20. It also defines stored procedures as reusable SQL code that can be saved and have parameters passed to them, and gives a sample stored procedure to select all customers.

Uploaded by

Payal Mohanty
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/ 2

The SQL EXISTS Operator

The EXISTS operator is used to test for the existence of any record in a subquery.

The EXISTS operator returns true if the subquery returns one or more records.

EXISTS Syntax

SELECT column_name(s)

FROM table_name

WHERE EXISTS

(SELECT column_name FROM table_name WHERE condition);

Demo Database

Below is a selection from the "Products" table in the Northwind sample database:

SQL EXISTS Examples


The following SQL statement returns TRUE and lists the suppliers with a
product price less than 20:

Example
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierI
D = Suppliers.supplierID AND Price < 20);

What is a Stored Procedure?

A stored procedure is a prepared SQL code that you can save, so the code can be reused
over and over again.

So if you have an SQL query that you write over and over again, save it as a stored
procedure, and then just call it to execute it.
You can also pass parameters to a stored procedure, so that the stored procedure can act
based on the parameter value(s) that is passed.

Stored Procedure Syntax

CREATE PROCEDURE procedure_name

AS

sql_statement

GO;

Execute a Stored Procedure

EXEC procedure_name;

Stored Procedure Example


The following SQL statement creates a stored procedure named
"SelectAllCustomers" that selects all records from the "Customers" table:

Example
CREATE PROCEDURE SelectAllCustomers
AS
SELECT * FROM Customers
GO;

Execute the stored procedure above as follows:

Example
EXEC SelectAllCustomers;

You might also like