MySQL BASICS

Haebin Ethan Jeong·2020년 6월 15일
0

DDL (Data Define Language)

1. Starting the server

  • mysql.server start

2. Activating the SQL

  • mysql -u root -p
    - Here, p means password.

3. Creating the DB

  • CREATE DATABASE [database_name] CHARACTER SET[[character set];
  • CREATE DATABASE [database_name] CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

4. Using the DB

  • use mysql_test;

5. Checking the tables.

  • show tables;
  • At first, it is an empty set. OBVIOUSLY.
  • EX) 1111w33w

6. Creating the Table

  • CREATE TABLE[table] (column1, column2...)
    - EX) CREATE TABLE books (id INT NOT NULL, name VARCHAR(30))
    • Altering the Table:
      • ALTER TABLE[table] ADD[column][datatype]
        - Ex) ALTER TABLE books ADD published_at DATE

7. Explaing the table

  • explain [table name]

8. Deleting the Table

  • DROP TABLE books;
  • Every time you drop your table (not recommended), you need to migrate in order to upload to you DB.

DML (Data Manipulation Language)

1. Adding values to Your Table

  • INSERT INTO books VALUES(1, 'Python', '2020-03-01');

Seeing the Table All at Once

  • SELECT * FROM [table name];

Updating the Table

  • UPDATE books SET published_at = '2020-03-03' WHERE id=2;

Deleting the Table

  • DELETE FROM [table name] WHERE [condition];

TCL (Transaction Control Language)

COMMIT;

  • To mark the changes as permanent.

ROLLBACK;

  • To restore the database to last commited state.

SAVEPOINT;

  • To temporarily save a transaction so that you can rollback to that point whenever required.
profile
I'm a Junior studying Economics and Computer Science at Vanderbilt University.

0개의 댓글