Friday, August 28, 2015

SQL - Creating Tables



create table employee
(first varchar(15),
last varchar(20),
age number(3),
address varchar(30),
city varchar(20),
state varchar(20));

Common Data types --
char(size) -- fixed lenght character string
varchar(size) -- variable lenght character string
number(size) -- number value with max number of column digits
date -- date value
number(side, d) -- number value with max digits to right of decimal

create table myemployees_RDP0680                  
(firstname varchar(15),
 lastname varchar(20),
title varchar(30),
age number(3),
salary number(7));


SQL -- conditional selections

In the last example the condition was first should equal 'Eric'. Besides equal here are other conditional clauses used in SQL:



= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal to
LIKE pattern matching operator, use "%" as character wild card

Here is an example:



select first,
       last,
       city
  from empinfo
where city <>
  'Payson';



Tuesday, August 25, 2015

SQL -- Selecting Data



select *
                from empinfo
                where first = 'Eric'

The above examples SQL query selects all (*) columns from the empinfo table where the first name is Eric. See result of the query below.

 

SQL -- Table Basics



Table Basics

Database system contains one of more objects called tables. Tables are uniquely identified by name and comprised of columns and rows. Columns contain column name and data type. Rows contain the records or data for the column (see example weather data table).