当前位置: 首页 > 编程日记 > 正文

Mysql 操作技巧

  1. 复制表结构 + 表数据
    Mysql> create tables t2 like t1;
    Mysql> insert into t2 select * from t1;
  2. mysql 索引
    a、Alert Table 用来创建普通索引、Unique 唯一索引 (当前列数值不可重复) 或 Primary Key 主键索引
    Mysql> alter table table_name add index index_name(column_list);
    Mysql> alter table table_name add Unique(column_list);
    Mysql> alter table table_name add Primary Key(column_list);

    b、creat index (不可处理主键索引)
    Mysql> create index index_name on table_name(column_list);
    Mysql> create Unique index index_name on table_name(column_list);

    c、drop index(不可处理主键索引)
    Mysql> drop index index_name on table_name;

    d、alter table drop
    Mysql> alter table table_name drop index index_name;
    Mysql> alter table table_name drop primary key;

  3. mysql 视图
    创建视图 (视图可根据主表实时更新)
    Mysql> create view v_t1 as select * from t1 where id>4 and id <11;
    Mysql> show tables;
    Mysql> show create view v_t1;
    Mysql> drop view v_t1;

  4. Mysql 内置函数
    concat ("string1","string2") // 链接字符串
    lcase(STRING) // 转换小写
    ucase(string) // 转换大写
    length(string) //string 长度
    ltrim(string) // 去除 string 前面空格
    rtrim(string) // 去除 string 后面空格
    repeat(string,count) // 重复 string count 次
    replace(str,search_str,replace_str) //str 中用 replace_str 替换 search_str

  5. mysql 预处理语句
    设置 stmt1 预处理,传递一个数据作为 where 判断条件
    Mysql> prepare stmt1 from 'select * from t1 where id>?';
    设置一个变量
    Mysql> set @i=5;
    执行 stmt1 预处理
    Mysql> execute stmt1 using @i;
    删除预处理 stmt1
    Mysql> drop prepare stmt1;

  6. mysql 事务处理 (Engine=MyISAM 表引擎不支持事务机制)
    查看表引擎是否支持
    Mysql> show create table t1;
    设置表引擎为 innodb
    Mysql> alter table t1 engine=innodb;
    关闭自动提交功能
    Mysql> set autocommit=0;
    查看当前 autocommit 设置
    Mysql> select @@autocommit;
    提交
    Mysql> commit;
    从表 t1 中删除了一条记录
    Mysql> delete from t1 where id =11;
    此时做一个 p1 还原点
    Mysql> savepoint p1;
    再次从表 t1 中删除一条记录
    Mysql> delete from t1 where id =10;
    再次做一个 p2 还原点
    Mysql> savepoint p2;
    此时恢复到 p1 还原点,当然后面 p2 这些还原点自动失效
    Mysql> rollback to p1;
    退回到最原始的还原点
    Mysql>roolback;

  7. Mysql 存储 (批量处理)
    例子:创建存储 P1, 创建 100 个用户;
    Mysql> \d // 执行 “;” 临时替换为 “//”
    Mysql> create proceduce p1()
    ->begin
    ->set @i=1;
    ->while @i<100 do
    ->insert into t1(name) value(concat("user",@i));
    ->set @i=@i+1;
    ->end while;
    ->end//
    Mysql> \d ;
    查看存储
    Mysql> show procedure status\G
    Mysql> show create procedure p1\G
    执行
    Mysql> call p1();

  8. Mysql 触发器
    修改 delimiter 为 //
    Mysql> \d // 
    例子:创建触发器 tg1,当向 t1 表插入数据时,t2 表也被插入数据
    Mysql> create trigger tg1 before insert on t1 for each row
    ->begin
    ->insert into t2(name) values(new.name);
    ->end//
    Mysql> \d ;
    查看触发器
    Mysql> show triggers;
    删除触发器
    Mysql> drop trigger tg1;
    创建触发器 tg2,当向 t1 表删除数据时,t2 表也被删除数据
    Mysql> create trigger tg2 before delete on t1 for each row
    ->begin
    ->delete from t2 where name=old.name;
    ->end//

    创建触发器 tg3,当向 t1 表更新数据时,t2 表也被更新数据
    Mysql> create trigger tg3 before update on t1 for each row
    ->begin
    ->update t2 set name=new.name where name=old.name;
    ->end//

  9. 重排 auto_increment
    Mysql 数据库自动增长的 ID 恢复重新排序
    Mysql> alter table tablename auto_increment = 1;

    Other:
    联合查询
    Mysql> select * from t1 union select *from t2
    快速删除
    Mysql> truncate table tablename;

转载于:https://www.cnblogs.com/Mrhuangrui/p/4570475.html

相关文章:

JS实现复制到剪切板效果

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码&#xff1a; <!DOCTYPE html> <html lang"en"><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8" /><meta cha…

如何管理多个Python版本和虚拟环境

Addition January 2019: If you are coming back to this blog after upgrading to macOS Mojave please see this github issue for a solution to the common pyenv ‘zlib not available’ problem.此外&#xff0c;2019年1月&#xff1a;如果在升级到macOS Mojave之后又回到…

linux 下byte,char,unsigned char的区别

在linux中&#xff0c;对byte的定义为无符号char&#xff0c;而char默认为有符号char。 #ifndef BYTE #define BYTE unsigned char #endif以下ZZ百度知道&#xff1a; 在C中&#xff0c;默认的基础数据类型均为signed&#xff0c;现在我们以char为例&#xff0c;说明(signed) c…

词法作用域和动态作用域

JavaScript采用的是词法作用域 1.词法作用域 即函数定义时&#xff0c;即确定的作用域。js中的作用域链&#xff0c;在函数声明时候&#xff0c;就已经确定了&#xff0c;无论函数在何处调用&#xff0c;其作用域变量的查找都是按照定义是包含关系去查找。 2.动态作用域 变量的…

10-18 JS基础复习笔记

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.JS类型 Numbel String Boolean Symbol Null Undefined Object(Funtion,Array,Data,Regexp); 2.字符串转数字类型 "122" //122 var a 1 2; console.log(a) //3 3.null 和 u…

vue.js crud_如何使用VS Code和ADO.NET使用ASP.NET Core执行CRUD操作

vue.js crud介绍 (Introduction) In this article we are going to create a web application using ASP.NET Core MVC with the help of Visual Studio Code and ADO.NET. We will be creating a sample Employee Record Management System and performing CRUD operations on…

redis事物命令示例

命令示例&#xff1a; 1. 事务被正常执行&#xff1a;#在Shell命令行下执行Redis的客户端工具。/> redis-cli#在当前连接上启动一个新的事务。redis 127.0.0.1:6379>multiOK#执行事务中的第一条命令&#xff0c;从该命令的返回结果可以看出&#xff0c;该命令并没有立即执…

JS 函数 函数递归

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 重要&#xff1a;函数也是对象&#xff0c;你可以给它们添加属性或者更改它们的属性。 函数内部对象&#xff1a;arguments 解析&#xff1a;函数实际上是访问了函数体中一个名为 arguments 的内部对象…

swift设置启动图不现实_如何通过装饰房屋来开始在Swift中使用增强现实

swift设置启动图不现实by Ranadhir Dey由Ranadhir Dey 如何通过装饰房屋来开始在Swift中使用增强现实 (How to get started with augmented reality in Swift by decorating your home) If you’ve read my previous post, you already have a beautiful AR floor in your din…

可用于nodejs的SuperAgent(ajax API)

简单示例&#xff1a; import request from superagent;//引用声明 request.post(api).withCredentials()//跨域.end((err, res) > {if (res.ok) {const json JSON.parse(res.text);} else {console.log(获取失败);}}); 1、get 方式 当使用get请求传递查询字符串的时候&…

Java第四次实验

一、实验内容&#xff1a; 结对编程。运行TCP代码&#xff0c;结对进行&#xff0c;一人服务器&#xff0c;一人客户端&#xff1b;利用加解密代码包&#xff0c;编译运行代码&#xff0c;一人加密&#xff0c;一人解密&#xff1b; 集成代码&#xff0c;密后通过TCP发送。 二、…

JS 面向对象编程之原型(prototype)

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 function Person(first, last) {this.first first;this.last last; } Person.prototype.fullName function() {return this.first this.last; } Person.prototype.fullNameReversed function() {…

idea自动捕获_Smilefie:如何通过检测微笑来自动捕获自拍

idea自动捕获by Rishav Agarwal通过里沙夫阿加瓦尔 Smilefie&#xff1a;如何通过检测微笑来自动捕获自拍 (Smilefie: how you can auto-capture selfies by detecting a smile) Ten second takeaway: use Python and OpenCV to create an app that automatically captures a …

hiho 1015 KMP算法 CF 625 B. War of the Corporations

#1015 : KMP算法 时间限制:1000ms单点时限:1000ms内存限制:256MB描述 小Hi和小Ho是一对好朋友&#xff0c;出生在信息化社会的他们对编程产生了莫大的兴趣&#xff0c;他们约定好互相帮助&#xff0c;在编程的学习道路上一同前进。 这一天&#xff0c;他们遇到了一只河蟹&#…

React 组件绑定点击事件,并且传参完整Demo

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.传数组下标给点击事件Demo&#xff1a; const A 65 // ASCII character codeclass Alphabet extends React.Component {constructor(props) {super(props);this.handleClick this.handleClick.bind…

ScaleYViewPager

https://github.com/eltld/ScaleYViewPager 转载于:https://www.cnblogs.com/eustoma/p/4572925.html

node mongoose_如何使用Express,Mongoose和Socket.io在Node.js中构建实时聊天应用程序

node mongooseby Arun Mathew Kurian通过阿伦马修库里安(Arun Mathew Kurian) 如何使用Express&#xff0c;Mongoose和Socket.io在Node.js中构建实时聊天应用程序 (How to build a real time chat application in Node.js using Express, Mongoose and Socket.io) In this tut…

结对项目开发电梯调度 - 整体设计

一、系统介绍 1&#xff0e; 功能描述 本电梯系统用来控制一台运行于一个具有16层的大楼电梯&#xff0c;它具有上升、下降、开门、关门、载客的基本功能。 大楼的每一层都有&#xff1a; (1) 两个指示灯: 这两个指示灯分别用于指示当前所在的层数和电梯的当前状态&#xff…

3.分支结构与循环结构

1 程序结构 程序结构分为顺序结构、分支结构、循环结构。分支结构有&#xff1a;if结构&#xff0c;if....else结构&#xff0c;if...else if....else &#xff0c;if...else结构&#xff0c;switch结构&#xff1b;循环结构有&#xff1a;while循环&#xff0c;do....while循环…

微信小程序 实现复制到剪贴版功能

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 实现API&#xff1a; wx.setClipboardData(Object object) API说明&#xff1a;设置系统剪贴板的内容 属性类型默认值是否必填说明支持版本datastring 是剪贴板的内容 successfunction 否接口调用成功…

数据结构面试题编程题_您下次编程面试时应该了解的顶级数据结构

数据结构面试题编程题by Fahim ul Haq通过Fahim ul Haq Niklaus Wirth, a Swiss computer scientist, wrote a book in 1976 titled Algorithms Data Structures Programs.瑞士计算机科学家Niklaus Wirth在1976年写了一本书&#xff0c;名为《 算法数据结构程序》。 40 yea…

oracle使用小技巧

批量禁用触发器 SELECT ALTER TRIGGER || trigger_name || DISABLE; FROM all_triggers; 这样就生成了一个禁用语句列表&#xff0c;复制到sql脚本执行界面&#xff0c;批量执行即可&#xff0c;类似的&#xff0c;可以用all_tables来批量删除表。 转载于:https://www.cnblogs…

if for switch语句

顺序语句&#xff1a;一行行执行条件语句:选择分支if语句 1、 if&#xff08;....&#xff09;//括号内是判断条件 { //程序代码&#xff0c;运算等等 } 2、 if&#xff08;....&#xff09;//括号内是判断条件 { //程序代码&#xff0c;运算等等 } else//如果不满足条件则执…

Apache Unable to find the wrapper https - did you forget to enable it when you configured PHP?

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 Apache Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? 问题解决办法&#xff1a; 打开配置文件 php.ini &#xff0c; 如图&#xff1a; …

文件魔术数字_如何使用魔术脚手架自动创建文件并节省时间

文件魔术数字Before we begin: This article uses JavaScript / Node.js example code, but you can port these concepts to any language using the right tools.开始之前&#xff1a;本文使用JavaScript / Node.js示例代码&#xff0c;但是您可以使用正确的工具将这些概念移…

Sql Server统计报表案例

场景&#xff1a;查询人员指定年月工作量信息 USE [Test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[GetWorkLoadMain] year int, month int, UserId varchar(50) as begindeclare day varchar(50)set dayCAST(year as varchar)-RIGHT((00…

运行报表时提示输入用户名和密码

在AX2012运行报表是总是提示用户输入用户名和密码&#xff1a; 尝试输入登陆名和密码&#xff0c;点击查看报表&#xff0c;出现如下错误&#xff1a; 因为AX2012的报表使用的针对AX2012客制化的SSRS&#xff0c;而要求输入登录名和密码是SSRS报表的数据源设置导致的。在SSRS管…

CSS 文字,边框实现从左至右颜色渐变

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.文本从左至右颜色渐变 效果图&#xff1a; 2.边框从左至右颜色渐变 效果图&#xff1a; 实现代码&#xff1a; 1.文本从左至右颜色渐变实现代码&#xff1a; <!DOCTYPE html> <html>&l…

如何使用Create-React-App和自定义服务人员构建PWA

Note: This is not a primer on create-react-app or what a service worker is. This post assumes prior knowledge of both.注意&#xff1a;这不是create-react-app或服务工作者的入门。 这篇文章假定两者都有先验知识。 So, I recently had the opportunity to work on a…

inline-block空隙怎么解决

方法一&#xff1a;移除空格 元素间留白间距出现的原因就是标签段之间的空格&#xff0c;因此&#xff0c;去掉HTML中的空格&#xff0c;自然间距就木有了。考虑到代码可读性&#xff0c;显然连成一行的写法是不可取的&#xff0c;我们可以&#xff1a; <div class"spa…