- Some of the most common DBMS's (Database Management Systems):
- PostgreSQL
- MySQL
- Oracle Database
- SQLite
- Types cannot be mixed and are specified upon creation. (Statically Typed)
- A collection of data
- I.e. a phone book
- A method of accessing and manipulating that data
- A structured set of computerized data with an accessible interface
- DMS or Relational Database Management System refers to an interface
for the data.
- The database is the data itself and all of it. The DBMS is the UI for it.
- They're often referred to as the same thing
- The language we use to "talk" to our databases
- SQL is used to write inside of DBMS's such as MySQL
- There is a standard for how SQL should work, and all DBMS's are tasked with implementing that standard and making them work.
- It's very easy to switch after learning SQL
- What makes databases (DBMS) unique are the features they offer, not the language.
mysql-ctrl {command}start(will start mysql)stop(will stop mysql)cli(Will stop and then start mysql)- Stands for Command Line Interface
use {database_name}(Changes the database being used)source {database_filename}(Run code from a query file)desc {table}(Shows the contents of a table)- Shorthand for
SHOW COLUMNS FROM {tablename}
- Shorthand for
create {database_name}(Creates a database)drop {database_name}(permanently destroys a database)SELECT database()(Tells you the current database being used)show {tables | databases}(Shows all tables or databases)
A table is a collection of related data held in a structured format within a database.
- Columns (Headers)
| Numeric | String | Date |
|---|---|---|
| INT | CHAR | DATE |
| SMALLINT | VARCHAR | DATETIME |
| TINYINT | BINARY | TIMESTAMP |
| MEDIUMINT | VARBINARY | TIME |
| BIGINT | BLOB | YEAR |
| DECIMAL | TINYBLOB | |
| NUMERIC | MEDIUMBLOB | |
| FLOAT | LONGBLOB | |
| DOUBLE | TEXT | |
| BIT | TINYTEXT | |
| MEDIUMTEXT | ||
| LONGTEXT | ||
| ENUM |
- INT (whole number)
- varchar (variable-length string between 1-255 characters)
- Table names should be pluralized. It's because a table describes multiple of the thing, not just one.
CREATE TABLE tablename
(
column_name data_type,
column_name data_type,
);
/* Example: */
CREATE TABLE cats
(
name VARCHAR(100),
age INT
);Incorrect syntax:
INSERT INTO <tablename>(column, column)
VALUES (value, value);The preferred way of writing:
INSERT INTO <tablename>
(column,
column)
VALUES (value,
value);- The order which the columns are used matters, as the order for the values being inserted must be in the same order.
INSERT INTO <tablename>
(column, column)
VALUES (value, value),
(value, value),
(value, value);