SQL

SQL

Here are my SQL lessons, projects, and examples of SQL.

Resources

  • Goorm.io  It’s the alternative to Cloud9. (Cloud9 was purchased by Amazon, and is difficult to use now)

Commands

  • Start the CLI: mysql-ctl cli;
  • List available databases:  show databases;
  • Creating a database:  CREATE DATABASE database_name;
  • To drop a database:  DROP DATABASE database_name;
  • To use a database:  USE database_name;
  • To check which database is being used:  SELECT database();
  • To Create a Table: CREATE TABLE tablename ( column_name data_type, column_name data_type );
    Example: CREATE TABLE cats ( name VARCHAR(100), age INT );
  • To show tablenames:  SHOW TABLES
  • To show columns in a tablename:  SHOW COLUMNS FROM tablename;
    Alternative command:  DESC tablename;
  • To delete a table:  DROP TABLE tablename;
  • How to insert data into a table:  INSERT INTO table_name ( column_name ) VALUES ( data );
    Example:  INSERT INTO cats( name, age ) VALUES ( ‘Jetson’, 7 );
  • To see data in a table:  SELECT * FROM tablename;
  • Insert Multiple data into a table: INSERT INTO table_name ( column_name, column_name ) VALUES ( value, value ), ( value, value ), ( value, value );