Create Database
CREATE DATABASE bob;
(To Verify) SHOW DATABASES;
USE bob;
SHOW TABLES;
(None)
CREATE TABLE Checks Check # NUMERIC(6) NOT NULL, Payee VARCHAR(20) NOT NULL, Amount DECIMAL(6,2) NOT NULL, Remarks VARCHAR(20) NOT NULL;
INSERT INTO Checks VALUES
(‘I’, ‘MA’, ‘Bell’, ‘150’, ‘Have sons next time’);
etc…
Arithmetic Operators
(*), (/), (%), (+), (-) Order of Operations is multiplication, division, modulo, addition, and subtraction.
Place a Condition on a Query
WHERE clause = more selective queries
Ex: name = ‘Brown’ or number of hours > 100 or where
Expression
ex: SELECT Name, Address, Phone, FROM Addressbook;
or
where name = ‘Brown’
(Boolean)
How would you select different tables in a database?
select * from deposits
Note: no semicolon
Plus (+)
ex: add to prices
SELECT Item, Wholesale, (Wholesale + 0.15) FROM price;
How would you change order of columns?
SELECT payee, remarks, amount, check #, FROM checks;
Dostinct
SELECT DISTINCT amount FROM checks;
or
SELECT DISTINCT, amount, payee FROM checks;
Primary Keys
CREATE TABLE suppliers
( supplier_id int not null,
supplier_name char(50) not null,
contact_name char(50),
constraint suppliers_pk primary key
(supplier_id)
);Basic Query Syntax
Select
- almost always followed by from (SELECT names FROM people;)
Select *
SELECT ALL
- returns info in it’s own order
Putting all the data into one place makes it useful to …
What is a database?
A container made up of columns and rows to help organize data in a constructive way
SQL stands for …
Structured Query Language
Declarative Language
– statements are declared and the system executes those statements
What tells the program the query is complete?
Semicolon ;
Does spacing matter?
No
Are commands case sensitive?
No
Is data case sensitive?
Yes, it may
How do you change the order of a column?
SELECT payee, remarks, amount, check # FROM checks; (whatever order you would like)
Query Expression
Conditions
- in order to find a particular item or group of items in your database you need 1(+) condition(s)
Types of Databases
Relational, object oriented, and document based are a few of the most common,