03 - MySQL Flashcards
What is SQL?
Structured Query Language. It is a comprehensive database language. Standard for relational databases.
What is MySQL?
RDBMS. Created by MySQL AB and bought out by Sun Microsystems (Oracle). MySQL supports: Web applications, Open-Source, low overhead, large size table.
SQL: Login to mysql?
$ mysql -u root -p
SQL: List all current databases?
$ SHOW DATABASES;
SQL: Create database?
$ CREATE DATABASE [db_name];
SQL: Delete database?
$ DROP DATABASE [db_name];
SQL: Make database active?
$ USE [db_name];
SQL: Show tables in the current database?
$ SHOW TABLES;
SQL: Create table with three fields called Officers?
$ CREATE TABLE Officers (BadgeNo int, Name varchar(40), Rank varchar(10));
SQL: Insert entry into table?
$ INSERT INTO Officers VALUES (132, “Ann G”, “Dep”);
SQL: How to remove a table?
$ DROP TABLE [tbl_name];
Name Numeric Data Types?
- int - is used for integer (whole) numbers
- float - is used for floating point (decimal) numbers
Name Time Related Data Types?
- date
- time
- datetime
Date format: “yyyy-mm-dd”
Time format: “hh:mm:ss”
Name String Data Types?
- Char - fixed size (3 Bytes)
- Varchar - variable size
- text
Char and varchar are good up to 255 characters. If you wish to store more text than this you should use the text data type. This takes no arguments and gives a much larger storage capacity.
SQL: How to insert values from a CSV file?
LOAD DATA LOCAL INFILE ‘C:/Officers.csv’ INTO TABLE Officers FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”’;