Mysql 表 创建 / 删除(基础3)
创建表 语法:
#进入数据库
mysql> use mydb123;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mydb123 |
+------------+
1 row in set (0.00 sec)
#创建一个名为test的表
mysql> create table test(
-> id int,
-> name varchar(20)
-> );
Query OK, 0 rows affected (0.08 sec)
#使用 show tables; 查看创建的表
mysql> show tables;
+-------------------+
| Tables_in_mydb123 |
+-------------------+
| test |
+-------------------+
1 row in set (0.00 sec)
#使用 describe test; 查看表结构。
mysql> describe test;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.26 sec)
#使用 desc test; 查看表结构(常用方法)。
mysql> desc test;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
#使用 show create table test\G; 查看表结构(常用方法)。
mysql> show create table test\G;
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
ERROR:
No query specified
#使用 show create table test; 查看表结构。
mysql> show create table test;
+-------+---------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
#删表:drop table test;
mysql> show tables; #查看当前的表
+-------------------+
| Tables_in_mydb123 |
+-------------------+
| test |
+-------------------+
1 row in set (0.00 sec)
mysql> drop table test; #删除表的命令
Query OK, 0 rows affected (0.00 sec)
mysql> show tables; #验证删除结果
Empty set (0.00 sec)
mysql>
Mysql 表 创建 / 删除(基础3)的更多相关文章
- 解决在mysql表中删除自增id数据后,再添加数据时,id不会自增1的问题
https://blog.csdn.net/shaojunbo24/article/details/50036859 问题:mysql表中删除自增id数据后,再添加数据时,id不会紧接.比如:自增id ...
- 3.MySQL之创建/删除用户
登录mysql服务器后可使用grant命令来创建用户并赋予相关权限. mysql> use mysql; Reading table information for completion of ...
- Mysql 表创建语句
# 新建bigData数据库 CREATE DATABASE bigData; USE bigData; # 创建dept表 CREATE TABLE dept( id INT UNSIGNED PR ...
- MySQL表操作过程的基础代码解析
GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. MySQL 的表有很多种,对表的操作主要是增删改查,今天来浅谈一下这些操作的底层代码和流程,以下以 tmp table为例 ...
- MongoDB 数据库创建删除、表创建删除、数据增删改查
一.管理 mongodb 数据库:mongo 查看所有数据库列 表 show dbs 二. 创建数据库 创建 数据库 use student 如果真的想把这个数据库创建成功,(collections) ...
- Mysql表创建外键报错
数据库表A: CREATE TABLE task_desc_tab ( id INT(11) PRIMARY KEY NOT NULL COMMENT '自增主键' AUTO_INCREMENT, t ...
- mysql数据库创建删除带横杠的数据库名
mysql> create database d-d; ERROR 1064 (42000): You have an error in your SQL syntax; check the m ...
- [MySQL]表创建外键失败:ERROR 1005 (HY000): Can't create table (errno: 150)
在数据库中建立一个新表(表引擎为InnoDB)时, 需要用到外键, 所以就在建表的时候加了一句foreign key (column) references table_name.但是执行时出现 ER ...
- mysql表创建好后添加外键
命令:alter table 需加外键的表 add constraint 外键名 foreign key(需加外键表的字段名) referencnes 关联表名(关联字段名); 注意:外键名不能重复
随机推荐
- (转)centos6.5 bind-DNS服务器bind的搭建详解
centos6.5环境DNS-本地DNS服务器bind的搭建 域名系统(英文:Domain Name System,缩写:DNS)是因特网的一项服务.它作为将域名和IP地址相互映射的一个分布式数据库, ...
- SaltStack 和 Ansible 的简单比较
https://blog.csdn.net/nqxqxq/article/details/76154847 https://www.cnblogs.com/lgeng/p/6567424.html ...
- Linux 虚拟机的安全加固建议
1.修改用户的密码口令策略: [root@centos-73-1 chpaadmin]# cat /etc/login.defs |grep -i pass # passwd command) s ...
- git 简单的操作命令
1, 克隆已存在项目 => git clone url 2, 拉取代码 => git pull 3, 配置账号密码 git config --global user.email &quo ...
- ln: 创建符号链接 "/usr/bin/java": 文件已存在
执行下述命令创建软链接 #ln -s $JAVA_HOME/bin/java /usr/bin/java 出现下述错误提示: ln: 创建符号链接 "/usr/bin/java": ...
- react-native 安卓支持 gif动态图
需要在android/app/build.gradle文件中添加模块 //这一行没有的话得加上才行 compile "com.facebook.fresco:fresco:1.5.0&quo ...
- J2SE 8的流库 --- 转换流, 得到的还是流
流的转换, 按照条件过滤/映射/摊平/截取/丢弃/连接/去重/排序. 辅助方法 public static int myCompare(String x, String y) { if(x.lengt ...
- css-选择器性能
ID选择器 比如#header 类选择器 比如.promo 元素选择器 比如 div 兄弟选择器 比如 h2 + p 子选择器 比如 li > ul 后代选择器 比如 ul a 7. 通用选择器 ...
- vscode-nextgenas编译配置
文档:https://github.com/BowlerHatLLC/vscode-nextgenas/wiki/asconfig.json asconfig.json { "config& ...
- Reduction: the word AT
Reduction: the word AT Share Tweet Share Tagged With: AT Reduction Study the AT reduction. There ar ...