How to create alter and insert data in to tables in Oracle, SQL Server, DB2, Sybase, Teradata, MySQL, Postgre SQL.

SQL for BEGINNERS
and DUMMIES

What is SQL, Table,
Database and RDBMS


What is Relational Database

PRIMARY KEY
FOREIGN KEY


Creating Tables and
Inserting Data

CREATE
ALTER
INSERT


Data Reading SQL
Funtions with Examples

SELECT
COUNT
DISTINCT
SUM | MIN | MAX
LIKE
WHERE

Creating Table

Table is collection of Columns and Rows. Each column required name, data type and length or precision. To create a table, first structure of table should be defined with a name. Then required rows should be insterted in to TABLE.


CREATE Table in ORACLE database

CREATE TABLE EMPLOYEE_INCOME
(EMPID NUMBER(10),
NAME VARCHAR2(20),
SALARY NUMBER(10));

Executing above SQL CREATE TABLE statement will create the following table structure with name EMPLOYEE_INCOME:
               
EMPIDNAMESALARY

ALTER TABLE in ORACLE database

ALTER TABLE EMPLOYEE_INCOME ADD BONUS NUMBER(10);

Executing above SQL ALTER TABLE statement will add the bonus column to existing EMPLOYEE_INCOME table, now it looks like the following:

EMPID NAME SALARY BONUS

SQL to INSERT RECORDS in to TABLE

INSERT INTO EMPLOYEE_INCOME
(EMPID, NAME, SALARY, BONUS)
VALUES
(1, 'Bill', 10000, 1000);


EMPID NAME SALARY BONUS
1 Bill 10000 1000

INSERT ALL
INTO EMPTBL (EMPID, NAME, SALARY, BONUS) VALUES (1, 'Bill', 10000, 1000)
INTO EMPTBL (EMPID, NAME, SALARY, BONUS) VALUES (2, 'Mike', 20000, 2000)
INTO EMPTBL (EMPID, NAME, SALARY, BONUS) VALUES (3, 'Samson', 30000, 3000)
INTO EMPTBL (EMPID, NAME, SALARY, BONUS) VALUES (5, 'Kevin', 50000, 5000)
SELECT * FROM EMPLOYEE_INCOME;


EMPID NAME SALARY BONUS
1 Bill 10000 1000
2 Mike 20000 2000
3 Samson 30000 3000
5 Kevin 50000 5000

Create another table named: EMPLOYEE_DETAILS with the data by following above setps

EMPID NAME CITY
1 Bill Los Angeles
2 Mike Los Angeles
3 Samson Portland
4 John Orlando