reenadak

2018-11-25_mysql_using command line

Nov 25th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. -- Database-Level
  2. DROP DATABASE databaseName -- Delete the database (irrecoverable!)
  3. DROP DATABASE IF EXISTS databaseName -- Delete if it exists
  4. CREATE DATABASE databaseName -- Create a new database
  5. CREATE DATABASE IF NOT EXISTS databaseName -- Create only if it does not exists
  6. SHOW DATABASES -- Show all the databases in this server
  7. USE databaseName -- Set the default (current) database
  8. SELECT DATABASE() -- Show the default database
  9. SHOW CREATE DATABASE databaseName -- Show the CREATE DATABASE statement
  10.  
  11. -- Table-Level
  12. DROP TABLE [IF EXISTS] tableName, ...
  13. CREATE TABLE [IF NOT EXISTS] tableName (
  14. columnName columnType columnAttribute, ...
  15. PRIMARY KEY(columnName),
  16. FOREIGN KEY (columnNmae) REFERENCES tableName (columnNmae)
  17. )
  18. SHOW TABLES -- Show all the tables in the default database
  19. DESCRIBE|DESC tableName -- Describe the details for a table
  20. ALTER TABLE tableName ... -- Modify a table, e.g., ADD COLUMN and DROP COLUMN
  21. ALTER TABLE tableName ADD columnDefinition
  22. ALTER TABLE tableName DROP columnName
  23. ALTER TABLE tableName ADD FOREIGN KEY (columnNmae) REFERENCES tableName (columnNmae)
  24. ALTER TABLE tableName DROP FOREIGN KEY constraintName
  25. SHOW CREATE TABLE tableName -- Show the CREATE TABLE statement for this tableName
  26.  
  27. -- Row-Level
  28. INSERT INTO tableName
  29. VALUES (column1Value, column2Value,...) -- Insert on all Columns
  30. INSERT INTO tableName
  31. VALUES (column1Value, column2Value,...), ... -- Insert multiple rows
  32. INSERT INTO tableName (column1Name, ..., columnNName)
  33. VALUES (column1Value, ..., columnNValue) -- Insert on selected Columns
  34. DELETE FROM tableName WHERE criteria
  35. UPDATE tableName SET columnName = expr, ... WHERE criteria
  36. SELECT * | column1Name AS alias1, ..., columnNName AS aliasN
  37. FROM tableName
  38. WHERE criteria
  39. GROUP BY columnName
  40. ORDER BY columnName ASC|DESC, ...
  41. HAVING groupConstraints
  42. LIMIT count | offset count
  43.  
  44. -- Others
  45. SHOW WARNINGS; -- Show the warnings of the previous statement
Advertisement
Add Comment
Please, Sign In to add comment