SQL Operators: Bookstore Inventory Database
SQL Operators: Bookstore Inventory Database
We will first of all create a bookstore table and fill it with dummy data and utilize that to learn
about different types of operators.
● CREATE TABLE Books starts the command to create a new table named 'Books'.
● Inside the parentheses, we define the columns and their data types:
● BookID INT PRIMARY KEY: An integer column for the book ID, set as the
primary key.
● Title VARCHAR(100): A variable character string column for the book title, with
a maximum length of 100 characters.
● Author VARCHAR(100): A column for the author's name, with a maximum
length of 100 characters.
● Genre VARCHAR(50): A string column for the genre, with a maximum length of
50 characters.
● Price DECIMAL(5, 2): A decimal column for the price, allowing up to 5 digits
with 2 decimal places.
● Quantity INT: An integer column for the quantity of books in stock.
● PublicationYear INT: An integer column for the publication year.
Operators
1. Arithmetic Operators
● This query increases the price of each book by 5 and displays the new price alongside
the title.
● This calculates the total stock value of each book (price multiplied by quantity).
2. Wildcard Operators
● Wildcard operators are used with the LIKE operator for pattern matching in strings.
● Finds all books with 'and' in their title, such as "Pride and Prejudice".
● Matches titles like "The Great Gatsby" (where the underscore represents any single
character).
3. Logical Operators
Example (AND):
SELECT * FROM Books WHERE Genre = 'Fiction' AND Price < 20;
Selects all fiction books priced below $20.
Example (OR):
● Retrieves all books that are either in the 'Fiction' or 'Sci-Fi' genre.
Example (NOT):
● These operators are used for range checking and matching a list of values, respectively.
Example (BETWEEN):
Example (IN):
● Retrieves all books that are in either the 'Fiction' or 'Romance' genres.