MySQL - Create Tables

임재현·2021년 4월 27일
0

MySQL

목록 보기
2/52

Tables

A Database is a bunch of tables thats whre data is stored.

Create Table

--형식--
CREATE TABLE tablename
  (
    column_name data_type,
    column_name data_type
  );
-------

--EX--
create table cats(
	name varchar(100),
	age int
)

How to check it works? (Create Table)

  1. SHOW TABLES

    mysql> show tables;
    +-------------------+
    | Tables_in_cat_app |
    +-------------------+
    | cats              |
    +-------------------+
    1 row in set (0.00 sec)

    It tells us that there is a cat table but that's pretty much it doesn't say anything about the contents of that table what are the different columns init.

  2. SHOW COLUMS FROM <TABLE NAME>

    mysql> show columns from cats;
    +-------+--------------+------+-----+---------+-------+
    | Field | Type         | Null | Key | Default | Extra |
    +-------+--------------+------+-----+---------+-------+
    | name  | varchar(100) | YES  |     | NULL    |       |
    | age   | int          | YES  |     | NULL    |       |
    +-------+--------------+------+-----+---------+-------+
    2 rows in set (0.00 sec)

    or, use DESCRIBE <TABLE NAME>, DESC <TABLE NAME>

    mysql> describe cats;
    +-------+--------------+------+-----+---------+-------+
    | Field | Type         | Null | Key | Default | Extra |
    +-------+--------------+------+-----+---------+-------+
    | name  | varchar(100) | YES  |     | NULL    |       |
    | age   | int          | YES  |     | NULL    |       |
    +-------+--------------+------+-----+---------+-------+
    2 rows in set (0.00 sec)
    
    mysql> desc cats;
    +-------+--------------+------+-----+---------+-------+
    | Field | Type         | Null | Key | Default | Extra |
    +-------+--------------+------+-----+---------+-------+
    | name  | varchar(100) | YES  |     | NULL    |       |
    | age   | int          | YES  |     | NULL    |       |
    +-------+--------------+------+-----+---------+-------+
    2 rows in set (0.00 sec)

    차이점은 없다.

profile
임재현입니다.

0개의 댓글