SQL Cheat Sheet Sqlserver
SQL Cheat Sheet Sqlserver
SQL Cheat Sheet Sqlserver
www.databasestar.com
SELECT Query Modifying Data Create Table
SELECT col1, col2
FROM table Insert INSERT INTO tablename Create Table CREATE TABLE tablename (
JOIN table2 ON table1.col = table2.col (col1, col2...) column_name data_type
WHERE condition VALUES (val1, val2); );
GROUP BY column_name Insert from a
HAVING condition INSERT INTO tablename
Table
ORDER BY col1 ASC|DESC; (col1, col2...) Create Table with Constraints
SELECT col1, col2...
Set Operators
A A Rename Column sp_rename
'table_name.old_column_name',
B B
'new_column_name', 'COLUMN';
C D UNION: Shows unique
rows from two result sets. Add Constraint ALTER TABLE tablename ADD
CONSTRAINT constraintname
INNER JOIN: show all matching A A constrainttype (columns);
records in both tables. UNION ALL: Shows all
B B rows from two result sets.
Drop Constraint ALTER TABLE tablename
DROP CONSTRAINT constraintname;
LEFT JOIN: show all records from left A A
INTERSECT: Shows rows that
table, and any matching records from ALTER TABLE tablename
B B exist in both result sets. Rename Table
right table. RENAME TO newtablename;
C