You are on page 1of 2

Data Definition Language

(CREATE, ALTER, DROP)


Create / Delete Database Constraints
Create a database NULL/NOT NULL
CREATE DATABASE databasename Data Types in SQL Server
CREATE TABLE table_name (
Text data types: column1 datatype NULL | NOT NULL,..
Delete a database CHAR(size), VARCHAR(size),…. );
DROP DATABASE databasename
Number data types: PRIMARY KEY/UNIQUE
INT, NUMERIC (size), NUMERIC (p, s),… CREATE TABLE table_name (
column1 datatype NULL | NOT NULL,..
CONSTRAINT pk_name PRIMARY KEY |
Create / Alter / Delete Table Date data types:
UNIQUE (pk_col1, …)
Create a table in a database DATE, TIMESTAMP,… );
CREATE TABLE table_name (
column1 datatype, CHECK
column2 datatype, Data Types in Oracle CREATE TABLE table_name (
column3 datatype, Text data types: column1 datatype NULL | NOT NULL,..
.... CHAR(size), VARCHAR2(size),…. CONSTRAINT pk_name CHECK (condition)
); );
Number data types:
FOREIGN KEY
Add columns in an existing table INT, NUMBER (size), NUMBER (p, s),… CREATE TABLE table_name (
ALTER TABLE table_name column1 datatype NULL | NOT NULL,..
ADD column_name datatype; Date data types: CONSTRAINT fk_name FOREIGN KEY
DATE, TIMESTAMP,… (fk_col1, …) REFERENCES parent_table
Delete columns in an existing table (pk_col1,…)
ALTER TABLE table_name );
DROP COLUMN column_name;

Delete a table
DROP TABLE table_name;
Data Manipulation Language
(SELECT, INSERT, UPDATE, DELETE)

INSERT Statement
Populate values for all the columns
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
DELETE Statement
Populate selective columns
UPDATE Statement Delete rows in a table
INSERT INTO table_name (column1, column2
UPDATE table_name DELETE FROM table_name
, column3, ...)
VALUES (value1, value2, value3, ...); SET column1 = value1, column2 = value2, WHERE condition;
...
WHERE condition; Delete all data inside the table
Populate a table using another table /Bulk insert TRUNCATE TABLE table_name;
INSERT INTO table_name (column1, column2
, column3, ...)
SELECT (col1, col2, col3, ...)
FROM second_table;

You might also like