目录
数据库的操作(续1)
一、表的操作
1)create table 表名(字段名 字段类型(字段长度),字段 字段类型(字段长度),。。。。);
注:必须先选定库才能创建
MariaDB [(none)]> create database demo1;
Query OK, 1 row affected (0.027 sec)
MariaDB [(none)]> use demo1
Database changed
MariaDB [demo1]> create table tb_1
(id int primary key auto_increment,
door_name varchar(100),tel varchar(50));
Query OK, 0 rows affected (0.312 sec)
MariaDB [demo1]>
2)查询表:show tables;
MariaDB [demo1]> show tables;
+-----------------+
| Tables_in_demo1 |
+-----------------+
| student |
| tb_1 |
+-----------------+
2 rows in set (0.000 sec)
3)删除表 drop table student;
MariaDB [demo1]> drop table student;
Query OK, 0 rows affected (0.130 sec)
MariaDB [demo1]> show tables
-> ;
+-----------------+
| Tables_in_demo1 |
+-----------------+
| tb_1 |
+-----------------+
1 row in set (0.001 sec)
4)查看表结构 desc 表名;
MariaDB [demo1]> desc tb_1;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| door_name | varchar(100) | YES | | NULL | |
| tel | varchar(50) | YES | | NULL |