0% found this document useful (0 votes)
37 views

SQL Quick Reference III

1) The document discusses the Data Definition Language (DDL) and Data Manipulation Language (DML) in SQL Server and Oracle. 2) The DDL is used to define database schemas and includes commands like CREATE, ALTER, and DROP to create, modify, and delete databases, tables, columns, constraints. 3) The DML allows managing and retrieving data from databases and includes SELECT to query data, INSERT to add rows, UPDATE to modify rows, and DELETE to remove rows.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

SQL Quick Reference III

1) The document discusses the Data Definition Language (DDL) and Data Manipulation Language (DML) in SQL Server and Oracle. 2) The DDL is used to define database schemas and includes commands like CREATE, ALTER, and DROP to create, modify, and delete databases, tables, columns, constraints. 3) The DML allows managing and retrieving data from databases and includes SELECT to query data, INSERT to add rows, UPDATE to modify rows, and DELETE to remove rows.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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