SQL Examples

The examples below show you some SQL statments for creating tables, inserting data, searching data and dropping tables. Notes that SQL statements in PostgreSQL and Oracle may be different for the same problem.

Examples for PostgreSQL

CREATE TABLE Student
(
  name      VARCHAR(32),
  sid       CHAR(9),
  birthday  DATE,
  age       INT
);

INSERT INTO Student VALUES
(
  'Michael', '012010123', '1900-01-01', 13
);
INSERT INTO Student VALUES
(
  'Tom', '111223333', '1902-01-01', 11
);

SELECT name, sid FROM Student
WHERE age > 12;

DROP TABLE Student;

Examples for Oracle

CREATE TABLE Student
(
  name      VARCHAR(32),
  sid       CHAR(9),
  birthday  DATE,
  age       INT
);

INSERT INTO Student VALUES
(
  'Michael', '012010123', TO_DATE('1900-01-01', 'YYYY-MM-DD'), 13
);
INSERT INTO Student VALUES
(
  'Tom', '111223333', TO_DATE('1902-01-01', 'YYYY-MM-DD'), 11
);
 
SELECT name, sid FROM Student
WHERE age > 12;

DROP TABLE Student;