首页 > 数据库 > MySQL > 正文

mysql学习笔记之表的基本操作

2024-07-24 12:52:29
字体:
来源:转载
供稿:网友

创建表

create table 表名

create table if not exists 表名

mysql> create database company;Query OK, 1 row affected (0.00 sec)mysql> use company;Database changedmysql> create table if not exists t_dept( -> deptno int, -> dname varchar(20), -> loc varchar(40));Query OK, 0 rows affected (0.20 sec)mysql> show tables;+-------------------+| Tables_in_company |+-------------------+| t_dept |+-------------------+1 row in set (0.00 sec)mysql>

显示当前库下的所有表

show tables;

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

查看表的结构

describe 表名

简写

desc 表名

mysql> describe t_dept;+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| deptno | int(11) | YES | | NULL | || dname | varchar(20) | YES | | NULL | || loc | varchar(40) | YES | | NULL | |+--------+-------------+------+-----+---------+-------+3 rows in set (0.00 sec)mysql> desc t_dept;+--------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+--------+-------------+------+-----+---------+-------+| deptno | int(11) | YES | | NULL | || dname | varchar(20) | YES | | NULL | || loc | varchar(40) | YES | | NULL | |+--------+-------------+------+-----+---------+-------+3 rows in set (0.00 sec)

查看表的详细

show create table 表名

mysql> show create table t_dept;+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+| t_dept | CREATE TABLE `t_dept` ( `deptno` int(11) DEFAULT NULL, `dname` varchar(20) DEFAULT NULL, `loc` varchar(40) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 |+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)show create table t_dept /Gmysql> show create table t_dept /G*************************** 1. row *************************** Table: t_deptCreate Table: CREATE TABLE `t_dept` ( `deptno` int(11) DEFAULT NULL, `dname` varchar(20) DEFAULT NULL, `loc` varchar(40) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf81 row in set (0.00 sec)
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表