- 
                Notifications
    You must be signed in to change notification settings 
- Fork 547
SQL
        Nicholas O'Kelley edited this page Feb 12, 2024 
        ·
        2 revisions
      
    The details of the following page were initially written by @OneMiss
NOTE: this list may not show all snippets included with this repository. To view the most up-to-date listing, check the snippets file (here)[https://github.com/rafamadriz/friendly-snippets/blob/main/snippets/sql.json].
CREATE TABLE tableName (
  attribute(s)
);CREATE TABLE IF NOT EXISTS tableName (
  attribute(s)
);CREATE DATABASE name;CREATE DATABASE IF NOT EXISTS;INSERT INTO tableName (
  attribute(s)
) VALUES ( values )DROP TABLE tableName;DROP DATABASE dbName;DROP TABLE IF EXISTS tableName;DROP DATABASE IF EXISTS tableName;SHOW TABLES;SHOW DATABASES;SELECT attribute(s) FROM tableName;SELECT DISTINCT attribute(s)
  FROM tableName;SELECT attribute(s)
  FROM tableName
  WHERE condition;SELECT attribute(s)
  FROM tableName
  ORDER BY attribute(s) ASC|DESC;UPDATE tableName
  SET attribute(s)
  WHERE condition;DELETE FROM tableName
  WHERE condition;ALTER TABLE tableName
   intructions;ALTER TABLE tableName
  ADD COLUMN col_name;ALTER TABLE tableName
  ADD COLUMN col_name
  AFTER col_name;ALTER DATABASE dbName
  CHARACTER SET charset
  COLLATE utf8_unicode_ci;SELECT attribute(s)
  FROM tableName
  INNER JOIN tableName2
  ON match;SELECT attribute(s)
  FROM tableName
  RIGHT JOIN tableName2
  ON match;SELECT attribute(s)
  FROM tableName
  LEFT JOIN tableName2
  ON match;SELECT attribute(s)
  FROM tableName
  FULL JOIN OUTER tableName2
  ON match
  WHERE condition;SELECT attribute(s) FROM tableName
UNION
SELECT attribute(s) FROM tableName2;SELECT attribute(s) FROM tableName
UNION ALL
SELECT attribute(s) FROM tableName2;SELECT attribute(s)
  FROM tableName
  GROUP BY attribute(s);BACKUP DATABASE dbName
  TO DISK filepath;BACKUP DATABASE dbName
  TO DISK filepath
  WITH DIFERENTIAL;PRIMARY KEY(attribute)CONSTRAINT attribute PRIMARY KEY(attribute(s))FOREIGN KEY(attribute) REFERENCES tableName(attribute)CONSTRAINT attribute FOREIGN KEY (attribute(s))
  REFERENCES tableName(attribute)CHECK ( condition )CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';DELETE FROM mysql.user WHERE user = 'userName';GRANT ALL PRIVILEGES ON db.tb TO 'user_name'@'localhost';