MySQL在表中加入记录

(1)创建teacher表

 mysql> create table teacher

      -> (

      -> Id int (5) auto_increment not null primary key,

      -> name char(10) not null, 

      -> address varchar(50) default 'No.1 Mid school',

      -> year date

      -> );

  Query OK, 0 rows affected (0.02 sec)

  

  mysql> show tables;

  +------------------+

  | Tables_in_school |

  +------------------+

  | teacher          |

  +------------------+

  1 row in set (0.00 sec)

(2)显示表的结构

mysql> desc teacher;

+---------+-------------+------+-----+-----------------+----------------+

| Field   | Type        | Null | Key | Default         | Extra          |

+---------+-------------+------+-----+-----------------+----------------+

| Id      | int(5)      | NO   | PRI | NULL            | auto_increment |

| name    | char(10)    | NO   |     | NULL            |                |

| address | varchar(50) | YES  |     | No.1 Mid school |                |

| year    | date        | YES  |     | NULL            |                |

+---------+-------------+------+-----+-----------------+----------------+

4 rows in set (0.00 sec)

(3)开始仅仅创建一张空表,无内容,所以显示为空

  mysql> select * from teacher;

  Empty set (0.00 sec)

  

  mysql> show tables;

  +------------------+

  | Tables_in_school |

  +------------------+

  | teacher          |

  +------------------+

  1 row in set (0.00 sec)

(4)插入相关记录

  mysql> insert into teacher

      -> values (202, 'robot', 'ZhuHai', '2013-04-24');

  Query OK, 1 row affected (0.01 sec)

(5)插入NULL值

mysql> insert into teacher values(203, 'Rose', 'ZhuHai', NULL);

Query OK, 1 row affected (0.05 sec)



mysql> select * from teacher;

+-----+-------+---------+------------+

| Id  | name  | address | year       |

+-----+-------+---------+------------+

| 202 | robot | ZhuHai  | 2013-04-24 |

| 203 | Rose  | ZhuHai  | NULL       |

+-----+-------+---------+------------+

2 rows in set (0.00 sec)



mysql>

(6)输出了所有字段的信息

  mysql> select * from teacher;

  +-----+-------+---------+------------+

  | Id  | name  | address | year       |

  +-----+-------+---------+------------+

  | 202 | robot | ZhuHai  | 2013-04-24 |

  +-----+-------+---------+------------+

  1 row in set (0.00 sec)

  

  mysql>

 

你可能感兴趣的:(mysql)