Sql-Cheat-Sheet

Only available on StudyMode
  • Topic: SQL, Database, Data Manipulation Language
  • Pages : 4 (360 words )
  • Download(s) : 100
  • Published : December 12, 2012
Open Document
Text Preview









SQL Facts
SQL stands for Structured Query Language
SQL is pronounced “sequel”
SQL is declarative language
SQL is used to access & manipulate data in databases
Top SQL DBs are MS SQL Server, Oracle, DB2, and MySQL
Database Definitions
RDBMS (Relational Database Management System) –
Software that stores and manipulates data arranged in
relational database tables.
Table – A set of data arranged in columns and rows. The
columns represent characteristics of stored data and the
rows represent actual data entries.
How to select data from a table

SQL Commands Categories
Data Query Language (DQL)
 SELECT - Retrieve data from table(s)
Data Manipulation Language (DML)
 INSERT - Insert data into db table
 UPDATE - Update data in db table
 DELETE - Delete data from table
Data Definition Language (DDL)
 CREATE - Create db object (table, view, etc.)
 ALTER - Modify db object (table, view, etc.)
 DROP - Delete db object (table, view, etc.)
Data Control Language (DCL)
 GRANT - Assign privilege
 REVOKE - remove privilege
How to insert data in a table

SELECT
FROM
WHERE
Example:
SELECT FirstName, LastName, OrderDate
FROM Orders WHERE OrderDate > '10/10/2010'

INSERT INTO
() VALUES ()
Example:
INSERT INTO Orders
(FirstName, LastName, OrderDate) VALUES
('John', 'Smith', '10/10/2010')

How to update data in a table

How to delete data from a table

UPDATE
SET = , = , …
WHERE
Example:
UPDATE Orders
SET FirstName = 'John', LastName = 'Who' WHERE LastName='Wo'

DELETE FROM
WHERE
Example:
DELETE FROM Orders
WHERE OrderDate < '10/10/2010'

How to group data and use aggregates
SELECT , ()
FROM
WHERE
GROUP BY
Example:
SELECT LastName, SUM(OrderValue)
FROM Orders
WHERE OrderDate > '10/10/2010'
GROUP BY LastName

How to order data
SELECT
FROM
WHERE
ORDER BY
Example:
SELECT FirstName, LastName, OrderDate
FROM Orders
WHERE OrderDate > '10/10/2010'
ORDER BY...
tracking img