创建数据库并插入数据

2017-03-12  本文已影响0人  lupinwu

基本命令

show databases;
use information_schema;
show tables;
quit / exit;

创建mysql_test

CREATE DATABASE mysql_test;
use mysql_test;

新建数据表

CREATE TABLE 表的名字
(
列名a 数据类型(数据长度),
列名b 数据类型(数据长度),
列名c 数据类型(数据长度)
);

| ID | name | phone |
|-|-|
| 01 | Tom | 110110110 |
| 02 | Jack | 119119119 |
| 03 | Rose | 114114114 |

mysql> CREATE TABLE employee (id int(10),name char(20),phone int(12));
mysql> CREATE TABLE department
    -> (
    -> dpt_name CHAR(20),
    -> dpt_phone INT(12)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+----------------------+
| Tables_in_mysql_test |
+----------------------+
| department           |
| employee             |
+----------------------+
2 rows in set (0.00 sec)

数据类型

数据类型

插入数据

INSERT INTO 表的名字(列名a,列名b,列名c) VALUES(值1,值2,值3);
INSERT INTO employee(id,name,phone) VALUES(01,'Tom',110110110);

INSERT INTO employee VALUES(02,'Jack',119119119);

INSERT INTO employee(id,name) VALUES(03,'Rose');

mysql> SELECT * FROM employee;
+------+------+-----------+
| id   | name | phone     |
+------+------+-----------+
|    1 | Tom  | 110110110 |
|    2 | Jack | 119119119 |
|    3 | Rose |      NULL |
+------+------+-----------+
3 rows in set (0.00 sec)
上一篇 下一篇

猜你喜欢

热点阅读