博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql的基本操作
阅读量:4580 次
发布时间:2019-06-09

本文共 1710 字,大约阅读时间需要 5 分钟。

show databases; select database();show tables; desc table_name;  #这几个命令是必须要敲的

创建数据库有两种方法

第一种是用bash命令来创建再授权mysql用户这样也可以

第二种当然是用sql命令来创建了

create  database doyouknow (                        #创建表

id  int(8) unsigned not null primary key increment,                         #主键的区别就是insert into values的时候值只能是唯一的

name varchar(20) not null default "this is default information and show "  comment     "this is attructions"

)auto_increment = 100;

                               

  #insert 值  :              

insert into table_name   values (42 ,  "who are you");

insert into table_name values (null,"sfa"),(null,"fsfasf"),(null, "sdfa"),(null, "sdfap");

# 添加一个字段

alter table table_name add column_name varchar(90) not null default "this is default information"  comment "this is attructions";

#添加多个字段

alter table table_name add (

column1 varchar(88) not null default "I like to practice"  comment  "this is attructions"

column2 varchar(88) not null default "why  do you like to practice"  comment  "Does not affect"

column3 varchar(88) not null default "can not modify"  comment  "this is attructions"

);

删除一个/或多个字段

alter table table_name drop column colume_name1,drop column column_name2;

 

#修改字段名字跟类型的同时还可以加上  default "sdfkalj"  跟 comment   "sdfafkkk"     ,如果字段的值是字符串,那么修改字符段的类型的时候,那个类型一定是要可以装下字符串的类型就可以修改成功,否则反之。

alter table table_name change old_column_name new_column_name char(40) not null default "sdfa" comment "sdfa";

 

#修改字段的长度的同时还可以加上  default "sdfkalj"  跟 comment   "sdfafkkk"

alter table table_name modify column_name varchar(10) not null default "sfa" comment "sfa";

 

#修改表的名字

alter table old_table_name rename to new_table_name;

 

update table_name set  column_name  = replace(column_name,'old_column_values','new_column_values') where column_name like 'old_column_values';     #这个可以只删除一个字段的值

转载于:https://www.cnblogs.com/fyy-hhzzj/p/8635344.html

你可能感兴趣的文章
flume将数据发送到kafka、hdfs、hive、http、netcat等模式的使用总结
查看>>
分布式技术追踪 2017年第二期
查看>>
正向代理、反向代理
查看>>
python 写excal
查看>>
Behaviac
查看>>
转载--c++_istringstream类
查看>>
SPUtility.SendEmail
查看>>
phalcon: 过滤(Phalcon\Filter())
查看>>
CORS 头缺少 'Access-Control-Allow-Origin'问题
查看>>
2019年2月11日-日记
查看>>
判断计算符号集
查看>>
(一) 进程调度
查看>>
灵悟礼品网上专卖店——分析类似项目的优缺点
查看>>
Directory Opus(DO) 个人使用经验 1.0
查看>>
零基础HTML5游戏制作教程 第2章 简单图形的绘制
查看>>
Semantic ui 学习笔记 持续更新
查看>>
设计模式之单例模式的简单demo
查看>>
有人问:“为什么不能和前任联系?”
查看>>
随州博物馆
查看>>
Eplan PLC连接点-两两相连接方法
查看>>