Sei sulla pagina 1di 16

Table of Contents

Introduction................................................................................................................................ 2
Links ............................................................................................................................................ 2
Oracle - SQL ................................................................................................................................ 3
SQL Server - T-SQL .................................................................................................................... 4
MySQL - SQL ............................................................................................................................... 5
Oracle - SQL - Insert .................................................................................................................... 6
SQL Server - T-SQL - Insert.......................................................................................................... 7
MySQL - SQL - Insert ................................................................................................................... 9
Screenshots .............................................................................................................................. 10
Screenshots - SQL Server - T SQL.............................................................................................. 10
Screenshots - MySQL - SQL....................................................................................................... 13

Introduction

When you think of learning SQL the below topics need to be learned and understood
in the beginning : DDL, DML , DCL and TCL
The "Links" section would give you further support
Assuming you are beginner or have not tried the SQL on other databases
The simplest idea, that I had, was to create the Oracle Tables on other databases.
That gave me good practise
This is a basic overview to get you started with SQL on Oracle, MS SQL Server and
MySQL in a one go

Links
The below two links uploaded with my article for getting started with SQL
https://de.scribd.com/doc/253309188/For-Learning-SQL-Install-Oracle-SQL-Server-andMySQL-on-Laptop-side-by-side-pdf
Part 1 to this article
https://de.scribd.com/doc/253321654/Getting-Started-with-Oracle-SQL-SQL-Server-T-SQLand-MySQL-SQL-pdf
Difference between :
http://www.orafaq.com/faq/what_are_the_difference_between_ddl_dml_and_dcl_comma
nds
Huge practise for SQL
http://www.w3schools.com/sql/
TIP : It would be wise to write the same SQL on various databases for better practise, if your
time permits
MS SQL Scripts (applies for 2005 & 2008)
http://www.forta.com/books/0672328674/
Scroll down. In the Appendix B you see "scripts.zip". Download it to practise for MS SQL TSQL
Oracle Apex
https://apex.oracle.com/en/
If you do not want to install database you can practise online using Oracle Apex
Click on "Get Started" -> Free Workspace -> Application Development -> Fill the details
(Workspace is the space or storage for your tables, created for you by Oracle Apex. Give a
6to8 characters, for example, 3 characters of your first name+test, like "guptest")

Oracle - SQL
EMP
CREATE TABLE "EMP" (
"EMPNO" VARCHAR2(10),
"ENAME" VARCHAR2(20),
"JOB" VARCHAR2(9),
"MGR" VARCHAR2(10),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" VARCHAR2(4),
CONSTRAINT "EMP_PK" PRIMARY KEY ("EMPNO")
USING INDEX ENABLE
);

DEPT
CREATE TABLE "DEPT" (
"DEPTNO" VARCHAR2(4),
"DNAME" VARCHAR2(15),
"LOC" VARCHAR2(15),
CONSTRAINT "DEPT_PK" PRIMARY KEY ("DEPTNO")
USING INDEX ENABLE
);

SALGRADE
CREATE TABLE "SALGRADE" (
"GRADE" VARCHAR2(4) NOT NULL ENABLE,
"LOSAL" NUMBER(7,2),
"HISAL" NUMBER(7,2),
CONSTRAINT "SALGRADE_PK" PRIMARY KEY ("GRADE")
USING INDEX ENABLE
);
ALTER TABLE "EMP" ADD CONSTRAINT "emp_mgr_fk" FOREIGN KEY ("MGR")
REFERENCES "EMP" ("EMPNO") ENABLE;
ALTER TABLE "EMP" ADD CONSTRAINT "emp_dept_fk" FOREIGN KEY ("DEPTNO")
REFERENCES "DEPT" ("DEPTNO") ENABLE;

ADDRESSES
CREATE TABLE "ADDRESSES" (
"ADDRESS_ID" VARCHAR2(10),
"STREET_ADDRESS" VARCHAR2(20),
"CITY" VARCHAR2(20),
"ST" VARCHAR2(5),
"COUNTRY" VARCHAR2(10)
CONSTRAINT "ADD_PK" PRIMARY KEY ("ADDRESS_ID") USING INDEX ENABLE
);

SQL Server - T-SQL


Note : Select the database in which you want to create the tables
Note : In this example the default Schema "dbo" is used. Later on, you create a Schema
and in that Schema the User Tables should be created (good practise). See the Screenshot
section for SQL Server to understand it
CREATE TABLE emp (
empno nvarchar (10) NOT NULL primary key,
ename nvarchar (20) ,
job
nvarchar (10) ,
mgr nvarchar (10),
hiredate date ,
sal
money ,
comm money
NULL,
deptno
nvarchar (4) NULL,
);
CREATE TABLE dept (
deptno nvarchar(4) NOT NULL primary key,
dname nvarchar(15) ,
loc nvarchar(15) ,
);
CREATE TABLE salgrade (
grade nvarchar(4) NOT NULL primary key,
losal money NULL,
hisal money NULL,
);
ALTER TABLE EMP ADD FOREIGN KEY (MGR) REFERENCES EMP (EMPNO);
ALTER TABLE EMP ADD FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO);

ADDRESSES
CREATE TABLE addresses (
address_id nvarchar(10)not null primary key,
street_address nvarchar(20),
city nvarchar(20),
st nvarchar(5),
country nvarchar(10)
);

MySQL - SQL
EMP
CREATE TABLE test.EMP (
EMPNO varchar(10) NOT NULL primary key,
ENAME VARCHAR(10),
JOB VARCHAR(10),
MGR VARCHAR(10),
HIREDATE DATE NOT NULL,
SAL decimal(7,2),
COMM decimal(7,2),
DEPTNO varchar(4)
);

DEPT
USE test;
CREATE TABLE DEPT (
DEPTNO varchar(4) not null primary key,
DNAME VARCHAR(15),
LOC VARCHAR(15)
);
SALGRADE
use test;
CREATE TABLE SALGRADE (
GRADE varchar(4) NOT NULL primary key,
LOSAL decimal(7,2),
HISAL decimal(7,2)
);
ALTER TABLE EMP ADD FOREIGN KEY (MGR) REFERENCES EMP (EMPNO);
ALTER TABLE EMP ADD FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO);

ADDRESSES
USE test;
CREATE TABLE ADDRESSES (
ADDRESS_ID VARCHAR(10) not null primary key,
STREET_ADDRESS VARCHAR(20),
CITY VARCHAR(20),
ST VARCHAR(5),
COUNTRY VARCHAR(10),
);

Oracle - SQL - Insert


Salgrade
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (1,700,1200);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (2,1201,1400);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (3,1401,2000);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (4,2001,3000);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (5,3001,9999);
Dept
INSERT INTO dept (DEPTNO,DNAME,LOC) VALUES (10,'ACCOUNTING','NEW YORK');
INSERT INTO dept (DEPTNO,DNAME,LOC) VALUES (20,'RESEARCH','DALLAS');
INSERT INTO dept (DEPTNO,DNAME,LOC) VALUES (30,'SALES','CHICAGO');
INSERT INTO dept (DEPTNO,DNAME,LOC) VALUES (40,'OPERATIONS','BOSTON');
Emp
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7839,'KING','PRESIDENT',null,to_date('11/17/1981','mm/dd/yyyy'),5000,null,10);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7698,'BLAKE','MANAGER',7839,to_date('05/01/1981','mm/dd/yyyy'),2850,null,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7782,'CLARK','MANAGER',7839,to_date('06/09/1981','mm/dd/yyyy'),2450,null,10);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7566,'JONES','MANAGER',7839,to_date('04/02/1981','mm/dd/yyyy'),2975,null,20);

INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES


(7788,'SCOTT','ANALYST',7566,to_date('12/09/1982','mm/dd/yyyy'),3000,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7902,'FORD','ANALYST',7566,to_date('12/03/1981','mm/dd/yyyy'),3000,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7369,'SMITH','CLERK',7902,to_date('12/17/1980','mm/dd/yyyy'),800,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7499,'ALLEN','SALESMAN',7698,to_date('02/20/1981','mm/dd/yyyy'),1600,300,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7521,'WARD','SALESMAN',7698,to_date('02/22/1981','mm/dd/yyyy'),1250,500,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7654,'MARTIN','SALESMAN',7698,to_date('09/28/1981','mm/dd/yyyy'),1250,1400,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7844,'TURNER','SALESMAN',7698,to_date('09/08/1981','mm/dd/yyyy'),1500,0,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7876,'ADAMS','CLERK',7788,to_date('01/12/1983','mm/dd/yyyy'),1100,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7900,'JAMES','CLERK',7698,to_date('12/03/1981','mm/dd/yyyy'),950,null,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7934,'MILLER','CLERK',7782,to_date('01/23/1982','mm/dd/yyyy'),1300,null,10);

SQL Server - T-SQL - Insert


Dept Insert
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (10,'ACCOUNTING','NEW YORK');
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (20,'RESEARCH','DALLAS');
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (30,'SALES','CHICAGO');
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (40,'OPERATIONS','BOSTON');

Emp Insert
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7839,'KING','PRESIDENT',null,'11/17/1981',5000,null,10);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7698,'BLAKE','MANAGER',7839,'05/01/1981',2850,null,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7782,'CLARK','MANAGER',7839,'06/09/1981',2450,null,10);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7566,'JONES','MANAGER',7839,'04/02/1981',2975,null,20)
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7788,'SCOTT','ANALYST',7566,'12/09/1982',3000,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7902,'FORD','ANALYST',7566,'12/03/1981',3000,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7369,'SMITH','CLERK',7902,'12/17/1980',800,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7499,'ALLEN','SALESMAN',7698,'02/20/1981',1600,300,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7521,'WARD','SALESMAN',7698,'02/22/1981',1250,500,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7654,'MARTIN','SALESMAN',7698,'09/28/1981',1250,1400,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7844,'TURNER','SALESMAN',7698,'09/08/1981',1500,0,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7876,'ADAMS','CLERK',7788,'01/12/1983',1100,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7900,'JAMES','CLERK',7698,'12/03/1981',950,null,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) VALUES
(7934,'MILLER','CLERK',7782,'01/23/1982',1300,null,10);

Salgrade Insert
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (1,700,1200);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (2,1201,1400);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (3,1401,2000);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (4,2001,3000);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (5,3001,9999);

MySQL - SQL - Insert


Dept Insert
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (10,'ACCOUNTING','NEW YORK');
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (20,'RESEARCH','DALLAS');
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (30,'SALES','CHICAGO');
INSERT INTO dept (DEPTNO,DNAME,LOC)
VALUES (40,'OPERATIONS','BOSTON');
Emp INSERT
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7839,'KING','PRESIDENT',null,'1981-11-17',5000,null,10);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,null,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7782,'CLARK','MANAGER',7839,'1981-06-09',2450,null,10);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7566,'JONES','MANAGER',7839,'1981-04-02',2975,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7788,'SCOTT','ANALYST',7566,'1982-12-09',3000,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7902,'FORD','ANALYST',7566,'1981-12-03',3000,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7369,'SMITH','CLERK',7902,'1980-12-17',800,null,20);

INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)


VALUES (7499,'ALLEN','SALESMAN',7698,'1981-02-20',1600,300,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7521,'WARD','SALESMAN',7698,'1981-02-22',1250,500,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,0,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7876,'ADAMS','CLERK',7788,'1983-01-12',1100,null,20);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7900,'JAMES','CLERK',7698,'1981-12-03',950,null,30);
INSERT INTO emp (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
VALUES (7934,'MILLER','CLERK',7782,'1982-01-23',1300,null,10);
Salgrade Insert
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (1,700,1200);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (2,1201,1400);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (3,1401,2000);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (4,2001,3000);
INSERT INTO salgrade (GRADE,LOSAL,HISAL) VALUES (5,3001,9999);

Screenshots
Screenshots - SQL Server - T SQL

Screenshots - MySQL - SQL