from w3cschool.com

1,modify the segment of table

alter table table_name add/drop var_name [var_type];

2,update

UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]

3,like==regexp

SELECT field1, field2,...fieldN table_name1, table_name2...
WHERE field1 LIKE condition1 [AND [OR]] filed2 = 'somevalue'

4,drop

DROP TABLE table_name ;

drop db_name;

5,create

mysql> CREATE TABLE tutorials_tbl(
   -> tutorial_id INT NOT NULL AUTO_INCREMENT,
   -> tutorial_title VARCHAR(100) NOT NULL,
   -> tutorial_author VARCHAR(40) NOT NULL,
   -> submission_date DATE,
   -> PRIMARY KEY ( tutorial_id )
   -> );

create db_name

6,delete

DELETE FROM table_name [WHERE Clause]

7,order by

SELECT field1, field2,...fieldN table_name1, table_name2...
ORDER BY field1, [field2...] [ASC [DESC]]

8,INDEX

9,temp table

mysql> CREATE TEMPORARY TABLE SalesSummary (
    -> product_name VARCHAR(50) NOT NULL
    -> , total_sales DECIMAL(12,2) NOT NULL DEFAULT 0.00
    -> , avg_unit_price DECIMAL(7,2) NOT NULL DEFAULT 0.00
    -> , total_units_sold INT UNSIGNED NOT NULL DEFAULT 0
);

10,create clone table

mysql> SHOW CREATE TABLE tutorials_tbl \G;

mysql> CREATE TABLE `clone_tbl` (...);

mysql> INSERT INTO clone_tbl (tutorial_id,
    ->                        tutorial_title,
    ->                        tutorial_author,
    ->                        submission_date)
    -> SELECT tutorial_id,tutorial_title,
    ->        tutorial_author,submission_date,
    -> FROM tutorials_tbl;

11,mysql info

SELECT VERSION( )   
SELECT DATABASE( )   current dbname
SELECT USER( )    current user
SHOW STATUS   
SHOW VARIABLES

12,AUTO_INCREMENT

reset table

insert table with id acsend

mysql> CREATE TABLE insect
    -> (
    -> id INT UNSIGNED NOT NULL AUTO_INCREMENT = 100,
    -> PRIMARY KEY (id),
    -> name VARCHAR(30) NOT NULL, # type of insect
    -> date DATE NOT NULL, # date collected
    -> origin VARCHAR(30) NOT NULL # where collected
);

13,primary key,unique // The UNIQUE constraint uniquely identifies each record in a database table.

CREATE TABLE person_tbl
(
   first_name CHAR(20) NOT NULL,
   last_name CHAR(20) NOT NULL,
   sex CHAR(10),
   PRIMARY KEY (last_name, first_name)  //last_name not permit to be the same as  first_name
);

CREATE TABLE person_tbl
(
   first_name CHAR(20) NOT NULL,
   last_name CHAR(20) NOT NULL,
   sex CHAR(10)
   UNIQUE (last_name, first_name)  // INSERT IGNORE INTO person_tbl (last_name, first_name),insert record existed will not report err,either real insert it
);

14,export &LOAD

SELECT a,b,a+b INTO OUTFILE '/tmp/result.text'

FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table;

---

mysql> LOAD DATA LOCAL INFILE 'dump.txt' INTO TABLE mytbl
-> FIELDS TERMINATED BY ':'
-> LINES TERMINATED BY '\r\n';

mysql> LOAD DATA LOCAL INFILE 'dump.txt'
-> INTO TABLE mytbl (b, c, a); //specialize the order

---

mysqlimport dbname tablename.txt

15,Function

SELECT AVG(Price) AS PriceAverage FROM Products;

SELECT COUNT(*) AS NumberOfOrders FROM Orders;

SELECT FIRST(column_name) FROM table_name;

SELECT LAST(column_name) FROM table_name;

SELECT MAX(column_name) FROM table_name;

SELECT MIN(column_name) FROM table_name;

SELECT SUM(column_name) FROM table_name;

SELECT Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID
GROUP BY ShipperName;

SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10;

SELECT UCASE(CustomerName) AS Customer, City
FROM Customers;

SELECT LCASE(CustomerName) AS Customer, City   //extract characters from a text field
FROM Customers;

SELECT LEN(column_name) FROM table_name;

select round(2.555,2) from dual;

SELECT NOW() FROM dual;

SELECT ProductName, Price, FORMAT(Now(),'YYYY-MM-DD') AS PerDate
FROM Products;

FOREIGN KEY constraint is used to prevent actions that would destroy links between tables

CREATE TABLE Orders
(
O_Id int NOT NULL,
OrderNo int NOT NULL,
P_Id int,
PRIMARY KEY (O_Id),
FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)
)

to be added...

Mysql note的更多相关文章

  1. 解决Cannot find MySQL header files under /usr/include/mysql的错误

    按照下面的步骤能成功,亲测.转帖,做笔记 编译php-5.5-6的mysql支持,出现Cannot find MySQL header files under /usr/include/mysql. ...

  2. linux 下mysql的启动 、调试、排错

    Linux 下 MySQL 启动与关闭 说明 一.启动 1.1  MySQL 进程 可以用ps 命令查看进程: [root@rac2 ~]# ps -ef|grep mysql root     21 ...

  3. Linux搭建PHP+MySQL+Apache环境

    环境: CentOS 6.4 MySQL详细安装可参考:http://www.cnblogs.com/yangxia-test/archive/2012/11/12/2766237.html Apac ...

  4. mysql下面的INSTALL-BINARY的内容,所有的mysql的配置内容都在这

    2.2 Installing MySQL on Unix/Linux Using Generic Binaries Oracle provides a set of binary distributi ...

  5. CentOS学习笔记--MySQL安装

    MySQL安装 Linux中使用最广泛的数据库就是MySQL,使用在线yum的方式安装的版本落后MySQL网站好几个小版本,本节亲自测试安装新版的MySQL. 测试机器环境: VMware Works ...

  6. 编译安装php Cannot find MySQL header files under /usr/include/mysql.

    编译php-5.5-6的mysql支持,出现Cannot find MySQL header files under /usr/include/mysql. Note that the MySQL c ...

  7. CentOS tengine mysql 5.7 php 5.6

    CentOS 7.x 编译安装 LNMP L 版本是 CentOS 7.x  x64版本, N 我们使用tengine 的最新版本,主要原因是因为tengine 默认支持很多的模块. M 这里我们选用 ...

  8. Mysql数据库安装和配置

    http://blog.csdn.net/pipisorry/article/details/46773507 Mysql数据库安装和配置.mysql语法.特殊符号及正则表达式的使用.MySQL备份与 ...

  9. mysql 案例 ~ mysql常见日志错误

    一 简介: mysql note级别日志汇总二错误系列  1 Aborted connection    1 [Note] Aborted connection 61 to db: 'unconnec ...

随机推荐

  1. php 递归创建目录、递归删除非空目录、迭代创建目录

    递归创建目录 方法一 function mk_dir($path){ if(is_dir($path)){ //参数本身是一个目录 return true; } if(is_dir(dirname($ ...

  2. 第二章、 Linux 如何学习

    第二章. Linux 如何学习 最近更新日期:2009/08/06 1. Linux当前的应用角色 1.1 企业环境的利用 1.2 个人环境的使用 Linux当前的应用角色 在第一章Linux是什么当 ...

  3. PHP测试用例练习

    本测试用例是一个判断三角形类型的练习测试用例,基于Netbeans 8.1IDE环境,和phpunit-5.2.10以及脚手架工具phpunit-skelgen-2.0.1.具体的环境搭建可参照: h ...

  4. [ZZ]计算机视觉、机器学习相关领域论文和源代码大集合

    原文地址:[ZZ]计算机视觉.机器学习相关领域论文和源代码大集合作者:计算机视觉与模式 注:下面有project网站的大部分都有paper和相应的code.Code一般是C/C++或者Matlab代码 ...

  5. Ruby--hash

    --将hash作为js方法 get_page_top_module('<%=@page_type%>', <%=@location_hash.to_json%>);

  6. html 符号大全

    ░ ▒ ▬ ♦ ◊ ◦ ♠ ♣ ▣ ۰•● ❤ ●•۰► ◄ ▧ ▨ ♨ ◐ ◑ ↔ ↕ ▪ ▫ ☼ ♦ ♧♡♂♀♠♣♥❤☜☞☎☏⊙◎ ☺☻☼▧▨♨◐◑↔↕▪ ▒ ◊◦▣▤▥ ▦▩◘ ◈◇♬♪♩♭♪の ...

  7. Worker 工作 后台js 工作

    <script type="text/javascript"> var w; function startWorker() { if (typeof (Worker) ...

  8. Delphi结构体数组指针的问题

    //这段代码在Delphi 2007和delphi 7下是可以执行的,所以正确使用结构体数组和指针应该是这样的,已验证 unit Unit1; interface uses Windows, Mess ...

  9. XPS to Blender 2.7x

    XPS to Blender 2.7x(Blender internal the easy way) Things we are gonna need are Blender 2.7x www.ble ...

  10. hibernate 数据库列别名自动映射pojo属性名

    package com.pccw.business.fcm.common.hibernate; import java.lang.reflect.Field; import java.math.Big ...