Monday, May 25, 2020

SQL - OFFSET And FETCH


--OFFSET FETCH

ORDER BY column_list [ASC |DESC]
OFFSET offset_row_count {ROW | ROWS}
FETCH {FIRST | NEXT} fetch_row_count {ROW | ROWS} ONLY

Example 

SELECT
    product_name,
    list_price
FROM
    production.products
ORDER BY
    list_price,
    product_name
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;

SELECT
    product_name,
    list_price
FROM
    production.products
ORDER BY
    list_price DESC,
    product_name
OFFSET 0 ROWS
FETCH FIRST 10 ROWS ONLY;

SQL - LIMIT And OFFSET


--To Retrieve A Portion Of Rows Returned By A Query, You Use The LIMIT And OFFSET Clauses.

SELECT column_list
FROM table1
ORDER BY column_list
LIMIT row_count OFFSET offset;

SELECT employee_id, first_name, last_name
FROM employees
ORDER BY first_name;

SELECT employee_id, first_name, last_name
FROM employees
ORDER BY first_name
LIMIT 5;

SELECT employee_id, first_name, last_name
FROM employees
ORDER BY first_name
LIMIT 5 OFFSET 3;

Friday, May 8, 2020

SQL - SCHEMA

Schema

A SQL database contains multiple objects such as tables, views, stored procedures, functions, indexes, triggers. We define SQL Schema as a logical collection of database objects. A user owns that owns the schema is known as schema owner. It is a useful mechanism to segregate database objects for different applications, access rights, managing security administration of databases. We do not have any restrictions on the number of objects in a schema.