USAGE

USAGE in SQL is a privilege type that specifies a user's ability to interact with a database object, such as a sequence or domain. Granting USAGE allows the user to use the specified object in SQL statements.

Example

CREATE TABLE customers (
customer_id INT,
customer_name VARCHAR(50),
customer_city VARCHAR(50)
);
INSERT INTO customers
(customer_id, customer_name, customer_city)
VALUES
(1, 'John Doe', 'New York'),
(2, 'Jane Doe', 'Los Angeles'),
(3, 'Mike Smith', 'Chicago');
SELECT * FROM customers;

Output

customer_id | customer_name | customer_city
-------------+---------------+--------------
1 | John Doe | New York
2 | Jane Doe | Los Angeles
3 | Mike Smith | Chicago

Explanation

The CREATE TABLE command is used to create a new table in the database. Three fields are specified: customer_id, customer_name, and customer_city.

The INSERT INTO command is then used to populate the table customers with data.

Finally, the SELECT command is used to retrieve all data from the customers table. It outputs the rows of the table, where each row represents a unique customer with their associated ID, name, and city.

Example

SELECT
FIRST_NAME,
LAST_NAME
FROM
EMPLOYEES
WHERE
SALARY > 5000;

Output

| FIRST_NAME | LAST_NAME |
|------------|-----------|
| John | Doe |
| Jane | Doe |

Explanation

The above SQL statement is extracting the column ‘FIRST_NAME’ and ‘LAST_NAME’ from the ‘EMPLOYEES’ table where the ‘SALARY’ is greater than 5000. The output table displays the result of the SQL statement.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.