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 -- 创 ...
随机推荐
- mac配置虚拟机的net模式
a.点击PD的偏好设置进入 1)选择net模式(shared)(相当于VM的V8虚拟机) 2)勾选将mac连入当前的网络 3)勾选在网络系统偏好设置中显示网络连接 b.点击mac的网络系统偏好设置,可 ...
- P4093 [HEOI2016/TJOI2016]序列
题目链接 题意分析 我们假设每一个数都有一个变动范围\([L_i,R_i]\) 那么我们令\(dp[i]\)表示以\(i\)结尾的最长不下降子序列的长度 那么就是\(dp[i]=max\{dp[j]+ ...
- 2016级算法第一次练习赛-B.朴素的中位数
朴素的中位数 题目链接:https://buaacoding.cn/problem/846/index 分析 题意很简单,就是给定了两个从小到大排好序的数组,找出这两个数组合起来的数据中的中位数. 方 ...
- 27.Next Permutation(下一个字典序列)
Level: Medium 题目描述: Implement next permutation, which rearranges numbers into the lexicographicall ...
- Docker安装Odoo实现快速迁移(四)
一. 安装postgres数据库 root@ubuntu-:~# docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --nam ...
- SQL数据库Replace的用法
关于数据库Replace的用法:Replace("字符串","要被替代的字符串","替代后的字符串")尝试过写法效果如下->修改前 效 ...
- 使用 json_serializable (flutter packages pub run build_runner build) 问题
命令: flutter packages pub run build_runner build 使用 build_runner 生成 .g.dart 文件 flutter packages pub r ...
- 第六次 Scrum Meeting
第六次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/4/10 22:00 30min 大运村1号楼6F 附Github仓库:WEDO 例会照片 工作情况总结(4.10 ...
- @media响应式布局
@media可以根据屏幕尺寸调节布局 @media screen and (min-width:100px) and (max-width:200px){ div { color:red; } } 在 ...
- unity3d vscode
原来unity3d里assets store有一个插件,下载就行了,插件名就叫vscode 下载完了之后,preference里就会出现,vscode,Enable Integration 这一项勾上 ...