mysql 笔记3
--建库
create database dsdb DEFAULT CHARACTER set utf8 collate utf8_general_ci;
/*
删除数据库
drop DATABASE 数据库名称
*/
drop DATABASE dsdb;
--显示数据库
show DATABASES;
--切换数据库
use 数据库名称;
use dsdb;
--建表
create table 表名(字段名 数据类型[长度] 属性[非空 默认值 主键 注释...]) charset=utf8,ENGINE=INNODB;
create table user_info(
user_id int(11) not null primary key auto_increment,
user_name VARCHAR(50) DEFAULT null,
user_sex char(2),
user_age int(3)
) charset=utf8,ENGINE=INNODB;
--删除表
drop TABLE 表名;
drop table user_info;
--复制表
create table 新表 select * from 旧表; //不能复制键
create table user_info_back select * from user_info;
create table 新表 like 旧表;
create table user_info_back2 like user_info;
--修改
alter table 表名 add 字段名 数据类型 属性; --添加字段
alter table user_info add user_address varchar(500) not null;
alter table 表名 change 旧的字段名称 新名称 数据类型 属性;--修改字段
alter table user_info change user_address my_address char(100) null;
--删除
alter table 表名 drop 字段名
alter table user_info drop my_address;
--添加主键
alter table 表名 add primary key (字段名);
alter table user_info_back add primary key (user_id);
--修改名称
alter table 表名 rename to 新名称;
alter table user_info_back rename to user_new_table;
数据操作:
插入数据:
insert into 表名([字段名称]) value ([列表值])
insert into 表名 set 字段名 = 值, 字段名= 值......ALTER
--复制表
insert into 表名1 select * from 表名2;
use yygdb;
show variables like 'autocommit';
--值0和OFF都是一样的,当然,1也就表示ON。
SET AUTOCOMMIT = 0;
insert into userinfo (useName,useSex,useAge)
VALUES
('托马斯','男',6),
('托马斯1','男',6),
('托马斯2','男',6),
('托马斯2','男',6),
('托马斯2','男',6),
('托马斯2','男',6),
('托马斯3','男',6);
ROLLBACK;
select * from userinfo
insert into userinfo set useName="詹姆斯",useSex='男',useAge=20;
create table userinfo_new select * from userinfo;
--修改
update 表名 set 字段名称=值,字段名称=值,字段名称=值.... where 条件表达式;
update userinfo set useSex='车' , useAge='100' where id<24 and useAge<18;
--删除 几种方式区别?
delete from 表名 where 条件表达式;
delete from userinfo where useName='托马斯2';//删除数据不会释放表空间
truncate table 表名;//删除数据释放表空间
truncate table userinfo;
DROP TABLE IF EXISTS order_table;
--查询
select * [字段名] from 表名 where 条件表达式;
--查询时 取部分数据(分页查询) limit
select * [字段名] from 表名 limit 数据条数;
select * from userinfo order by id DESC limit 2,3;
select * from userinfo limit (当前页数-1) * 每页条数, 每页条数;
select * from userinfo limit 8,4;
create table employee(
id SMALLINT(4) not null auto_increment,
employee_id INT(4) not null,
first_name varchar(25) not null,
last_name varchar(35),
email VARCHAR(55) not null,
salary decimal(8,2) not null,
primary key (id)
);
insert into employee VALUES(1,1,'bob','connwer','245532fdf',453.90),
(2,2,'bob2','connwehr','245532fdf',453.90),
(3,3,'bob3','conndfwer','245532fdf',453.90),
(4,4,'bob4','connwbfder','245532fdf',453.90);
创建视图 虚表(保护数据信息,不让别人随便查看,如工资)
create view employee_contact_info_view as
select first_name ,last_name,email from employee order by last_name asc;
select * from employee_contact_info_view;
show tables;
show create view employee_contact_info_view;
视图可以和所有子句和函数联合使用
新建视图,并给字段重新取名字
create view employee_view(firstname,lastname,emailaddress)as
select first_name,last_name,email from employee order by last_name asc;
alter view employee_contact_info_view(First_name,Last_name,Employee_id) as
select first_name,last_name,employee_id from employee order by last_name asc;
update employee_contact_info_view set Last_name='hahah' where Employee_id=1;
select * from information_schema.views;
drop view employee_view;
mysql 笔记3的更多相关文章
- MySQL笔记汇总
[目录] MySQL笔记汇总 一.mysql简介 数据简介 结构化查询语言 二.mysql命令行操作 三.数据库(表)更改 表相关 字段相关 索引相关 表引擎操作 四.数据库类型 数字型 字符串型 日 ...
- 涂抹mysql笔记-数据库中的权限体系
涂抹mysql笔记-数据库中的权限体系<>能不能连接,主机名是否匹配.登陆使用的用户名和密码是否正确.mysql验证用户需要检查3项值:用户名.密码和主机来源(user.password. ...
- centos7.2下安装Mysql笔记
centos7.2下安装Mysql笔记 安装 MySQL 适用于 CentOS 7.0 或以后版本: yum install mariadb mariadb-server 适用于 CentOS 6.8 ...
- MySQL笔记(六)游标练习
23.3.1 Trigger Syntax and Examples 意义不明的几道练习,留着备用. 感觉不好写,而且难以调试..不知道以后会不会有实际的应用场景. 环境:MySQL 笔记(三)由 t ...
- mysql 笔记(一)
mysql 笔记 预留 mysql> use mysql; mysql> grant all privileges on *.* to root@'%' identified by &q ...
- 【MySQL笔记】SQL语言四大类语言
SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL. 1. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句, ...
- Mysql 笔记二
Mysql 笔记二 Mysql 笔记二 Table of Contents 1. 前言 2. Master Thread 工作方式 2.1. 主循环(loop) 2.2. 后台循(backgroup ...
- 深入浅出mysql笔记---1、mysql下载安装
深入浅出mysql笔记---1.mysql下载安装 一.总结 一句话总结: linux下rpm安装即可 1.linux的wget命令作用? 下载文件的工具:比如wget http://cn.wordp ...
- 深入浅出mysql笔记---0、序
深入浅出mysql笔记---0.序 一.总结 一句话总结: 心得:买书之前建议先找找电子书,纸质书太难带了 1.开源作用? 开源对mysql的发展至关重要 2.mysql在2002年就全面支持了事务, ...
- 最全mysql笔记整理
mysql笔记整理 作者:python技术人 博客:https://www.cnblogs.com/lpdeboke Windows服务 -- 启动MySQL net start mysql -- 创 ...
随机推荐
- react的一些思考
在做好第一个需求之后,我接到了一个react写的产品,这让我异常的兴奋,终于能写react了 开始做的时候整体框架已经搭建好了,这让我有点小失落,我还以为我要开始搭框架了呢,没事,搭的也挺好的. 有了 ...
- P5283 [十二省联考2019]异或粽子 可持久化01Trie+线段树
$ \color{#0066ff}{ 题目描述 }$ 小粽是一个喜欢吃粽子的好孩子.今天她在家里自己做起了粽子. 小粽面前有 \(n\) 种互不相同的粽子馅儿,小粽将它们摆放为了一排,并从左至右编号为 ...
- hasattr(object, name)
查看object有没name属性 有返回True 没有返回 False
- JavaScript DOM编程艺术 笔记(二)语句操作
操作 var total = (1+4)*5; year = year +1; year++; var message = "i am" + "girl"; 是 ...
- Elasticsearch 因拷贝多余的jar到lib库导致无法启动的问题
因为需要测试,无意中拷贝了一个netty-buffer-4.1.16.Final.jar包放到es的lib目录下,晚上回家启动es的时候发现启动不起来了.检查日志发现如下错误. 其中有一句关键语句 C ...
- CSS: Multiple Attribute Selector [name="value"][name2="value2"]
this.document.querySelectorAll('div[id*="dayselector"][class*="x-autocontainer-innerC ...
- [BZOJ 4921][Lydsy1706月赛]互质序列
传送门 因为区间 gcd 的变换不会超过 log 个,所以我们可以暴力枚举区间起点,复杂度是 n*logn 的 #include <bits/stdc++.h> using namespa ...
- 洛谷 P4234 最小差值生成树(LCT)
题面 luogu 题解 LCT 动态树Link-cut tree(LCT)总结 考虑先按边权排序,从小到大加边 如果构成一颗树了,就更新答案 当加入一条边,会形成环. 贪心地想,我们要最大边权-最小边 ...
- LTE
LTE (telecommunication), Long Term Evolution, a telephone and mobile broadband communication standar ...
- nginx响应码
ngx.status = ngx.HTTP_CONTINUE (100) (first added in the v0.9.20 release)ngx.status = ngx.HTTP_SWITC ...