The SQL cheat sheet provides you with the most commonly used SQL statements for your reference. You can download the SQL cheat sheet as follows:
Update: Cheatsheets BETA is here! SQL, Structured Query Language, is a programming language designed to manage data stored in relational databases.SQL operates through simple, declarative statements.
Querying data from a table
Query data in columns c1, c2 from a table
Query all rows and columns from a table
Query data and filter rows with a condition
- The PL/SQL cheat sheet includes symbol syntax and methods to help you using PL/SQL.ORACLE PL/SQL is an extension of SQL language that combines the data manipulation power of SQL with the processing power of procedural language to create super-powerful SQL queries.
- The Comparitech SQL Cheat Sheet. There is a long list of options that you can put on a SELECT statement. This short guide has only covered the basic structure of the SELECT statement, which is the main tool of SQL’s Data Query Language. You can see a comprehensive list in the Comparitech MySQL Cheat Sheet (PDF). That sheet also includes the.
Query distinct rows from a table
Sort the result set in ascending or descending order
Skip offset of rows and return the next n rows
Group rows using an aggregate function
Filter groups using HAVING clause
Querying from multiple tables
Inner join t1 and t2
Left join t1 and t1
Right join t1 and t2
Perform full outer join
Produce a Cartesian product of rows in tables
Another way to perform cross join
Join t1 to itself using INNER JOIN clause
Using SQL Operators
Combine rows from two queries
Return the intersection of two queries
Subtract a result set from another result set
Query rows using pattern matching %, _
Query rows in a list
Query rows between two values
Check if values in a table is NULL or not
Managing tables
Create a new table with three columns
Delete the table from the database Magicard desktop id software mac download.
Add a new column to the table
Drop column c from the table
Add a constraint
Drop a constraint
Rename a table from t1 to t2
Rename column c1 to c2
Remove all data in a table
Using SQL constraints
Set c1 and c2 as a primary key Download adobe pdf printer driver mac os x.
Set c2 column as a foreign key
Make the values in c1 and c2 unique
Ensure c1 > 0 and values in c1 >= c2
Set values in c2 column not NULL
Modifying Data
Insert one row into a table
Insert multiple rows into a table
Insert rows from t2 into t1
Update new value in the column c1 for all rows
Update values in the column c1, c2 that match the condition
Delete all data in a table
Delete subset of rows in a table
Managing Views
Create a new view that consists of c1 and c2
Create a new view with check option
Create a recursive view
Create a temporary view
Delete a view
Managing indexes
Create an index on c1 and c2 of the t table
Create a unique index on c3, c4 of the t table
Drop an index
Managing triggers
Create or modify a trigger
WHEN
- BEFORE – invoke before the event occurs
- AFTER – invoke after the event occurs
EVENT
- INSERT – invoke for INSERT
- UPDATE – invoke for UPDATE
- DELETE – invoke for DELETE
TRIGGER_TYPE
- FOR EACH ROW
- FOR EACH STATEMENT
Delete a specific trigger
In first steps young DBA can greedily soak up all kinds of database knowledges: as RDBMS as NoSQL. We’re realising things like how table index works, how to optimize memory caching, write triggers and procedurs etc. But we still can forget a simple command to create user or show tables list. Also we can get stuck when switching from MySQL to PostgreSQL or whatever else, cause command syntax is different.
Sqlplus Cheat Sheet 2020
For this issue I lead a special cheatsheet table of DBMS commands. This table is splitted on few parts for each system I faced. I’ll try to update it as soon as I’ll start to explore other DBMS solutions.
Sqlplus Cheat Sheet Pdf
MySQL | PostgreSQL | Oracle Database | |
Shell command to ask MySQL command line | mysql –u admin -p | psql –U admin —password | sqlplus admin/password |
Create new user admin | CREATE USER ‘admin’@‘localhost’ IDENTIFIED BY ‘password’; | CREATE USER admin WITH PASSWORD ‘password’; | CREATE USER admin IDENTIFIED BY password |
List all available databases | SHOW DATABASES | l | cat /etc/oratab #from shell |
List all available tables in current database | SHOW TABLES | dt | SELECT table_name FROM all_tables |
List all users in RDBMS | SELECT User FROM mysql.user | du | select*from dba_users |
Check database grants for any user | SHOW GRANTS | dp | SELECT GRANTEE, OWNER, GRANTOR, PRIVILEGE,GRANTABLE FROM DBA_TAB_PRIVS; |
Switch to another database | USE database2 | connect database2 | sqlplus admin/password@localhost/database2 |
Read help about command syntax | HELP ‘select’ | h SELECT | HELP SELECT |
Execute shell command | ! pwd | ! pwd | Hard-to-explain Oracle scheduler |
Execute SQL script from file | source mydir/test.sql | i mydir/test.sql | echo @mydir/test.sql | sqlplus username/password@connect (only from command line, sorry) |
Get database size | SELECT data_length + index_length as“size” FROM information_schema.TABLES WHERE table_schema =“mydb” | SELECT pg_database_size(mydb); | Still hard to explain |
Check data storage directory | SHOW VARIABLES WHERE Variable_Name LIKE “%dir”; | SHOW data_directory; | SELECT value FROM v$parameter WHERE name =‘db_create_file_dest’ |
List all indexes | SELECT * FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = DATABASE(); | di | SELECT user_tables.table_name, user_indexes.index_name FROM user_tables JOIN user_indexes on user_indexes.table_name = user_tables.table_name ORDER by user_tables.table_name,user_indexes.index_name; |
Grant SELECT on all DB tables | GRANT SELECT ON mydb.* TO ‘user’@‘localhost’; | GRANT SELECT ON ALL TABLES IN SCHEMA public TO user; | So much hard to explain |
Set config parameter | SET parameter=value; | ALTER SYSTEM SET parameter = value; | ALTER SYSTEM SET parameter = value; |
Make a logical backup | mysql dump -h host -u user -pPassword db | pg_dump -h host -d db -U user -W | NO WAY! |
Return info about dead tuples at the table (PostgreSQL only) | SELECT relname, n_dead_tup, last_vacuum, last_autovacuum FROM pg_catalog.pg_stat_all_tables WHERE n_dead_tup >0 AND relname NOT LIKE ‘pg%’; | ||
Terminate all connections to database | SELECT CONCAT(‘KILL ‘,id,’;’) FROM information_schema.processlist WHERE user=’root’ INTO OUTFILE ‘/tmp/a.txt’; SOURCE /tmp/a.txt; | SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname=’ticktest’; | startup forse;(as sys) |