知识点汇总,常用的Mysql数据库操作语句大全

select CustomerNo from dbo.Customers;

推荐:

通配符的行使

零、客户管理:

select *from dbo.Customers;
select CustomerNo from dbo.Customers
where CustomerNo LIKE'[AQ]%';--[]表示中括号中内容任取其一,%指代任意多个字符
SELECT CustomerNo FROM Customers
WHERE CustomerNo LIKE '_TM00_';--_指代任意单个字符

1、新建客商:

拼接字段

>CREATE USER name IDENTIFIED BY ‘ssapdrow’;

1 select CustomerNo+'('+CustomerState+')' 
2 AS CustomerTitle
3 from dbo.Customers
4 ORDER BY CustomerNo DESC;--将两列合并成一列并取别名为CustomerTitle,按照CustomerNo降序排列

2、改变密码:

文本管理函数的选拔RT奥迪Q7IM和LTXC60IM

>SET PASSWORD FOR name=PASSWORD(‘fdddfd’);

1 SELECT RTRIM(CustomerNo)+'('+RTRIM(CustomerState)+')'
2 AS CustomerTitle
3 FROM Customers
4 ORDER BY CustomerNo DESC;--在上一条语句的基础上去掉字符串右边的空格

3、权限处理

排序OCR-VDEPRADO BY并以列号指代某一列

>SHOW GRANTS FOENVISION name;    //查看name客户权限

1 SELECT CustomerNo,CustomerShortName,CustomerState,Class from dbo.Customers
2 ORDER BY 4 DESC,2;

>GRANT SELECT ON db_name.* TO
name;    //给name用户db_name数据库的具备权限

NOT操作符,检索除某一项之外的有所数据

>REVOKE SELECT ON db_name.* TO
name;    //GRANT的反操作,去除权限;

SELECT CustomerNo FROM dbo.Customers
WHERE NOT CustomerNo LIKE'[QC]%'

一、数据库操作:

IN操作符,检索在有些条件限制内的数量

1、查看数据库:

SELECT CustomerNo,Class FROM dbo.Customers
WHERE CustomerNo IN ('ATM002','QTM104','ATM004')
ORDER BY 2 DESC;

>SHOW DATABASES;

文本管理函数UPPE奥迪Q5和LOWE揽胜的接纳,将列值转变为题写或许调换来小写

2、创制数据库:

SELECT UPPER(CustomerNo) AS CUS,Class FROM dbo.Customers
WHERE CustomerNo LIKE 'Cus%';

SELECT LOWER(CustomerNo) AS cus,Class FROM dbo.Customers
WHERE CustomerNo LIKE '_TM%'

>CREATE DATABASE db_name;  //db_name为多少库名

日子管理函数DATEPART的应用,取时间值中的某一项数据

3、使用数据库:

SELECT Created from dbo.Inspections
WHERE DATEPART(YY,Created)=2018;

>USE db_name;

会晤函数AVG,COUNT,MAX,MIN,SUMD的选取

4、删除数据库:

SELECT AVG(TotalAmount) AS AvgAmount FROM dbo.Inspections;

SELECT COUNT(*) AS CountNum FROM dbo.Customers
WHERE CustomerState='销售机会';
SELECT CustomerNo FROM dbo.Customers
WHERE CustomerState='销售机会';

SELECT MAX(TotalAmount) AS MaxAmount FROM dbo.Inspections;
SELECT * FROM dbo.Inspections WHERE TotalAmount='126000'

SELECT * FROM dbo.Inspections;
SELECT SUM(TotalVolumn) AS SumV FROM dbo.Inspections;
SELECT TotalAmount+TotalGrossWeight AS SumV FROM dbo.Inspections;

SELECT COUNT(*) AS countNo,
MIN(TotalVolumn) AS minTV,
MAX(TotalVolumn) AS maxTV,
AVG(TotalVolumn) AS avgTV
FROM dbo.Inspections

>DROP DATABASE db_name;

分组函数GROUP BY

二、创建表:

SELECT COUNT(*) AS countNO
FROM dbo.Customers
WHERE CustomerNo LIKE '_TM%'
GROUP BY CustomerState;

1、创建表:

对组处理标准函数HAVING,对已分组的组开展更为筛选

>CREATE TABLE table_name(

SELECT CustomerState,COUNT(*) AS countNo
FROM dbo.Customers
WHERE CustomerNo LIKE '_TM%'
GROUP BY CustomerState
HAVING CustomerState='产品认可';

>id TINYINT UNSIGNED NOT NULL
AUTO_INCREMENT,    //id值,无符号、非空、递增——独一性,可做主键。

内统一,联结五个表的询问语句

>name VARCHAR(60) NOT NULL

SELECT * FROM dbo.Quotations;
SELECT QuotationNo,QuotationStatus,Class
FROM Quotations,Customers
WHERE Quotations.CustomerNo=Customers.CustomerNo;

SELECT QuotationNo,QuotationStatus,Class
FROM Quotations INNER JOIN Customers
ON Quotations.CustomerNo=Customers.CustomerNo;

>score TINYINT UNSIGNED NOT NULL DEFAULT 0,    //设置暗中认可列值

将多表联结账和转账化为子查询语句

>PRIMARY KEY(id)

SELECT QuotationNo,QuotationStatus FROM Quotations,Customers
where Customers.CustomerState='销售机会'
AND Customers.CustomerNo=Quotations.CustomerNo;

SELECT QuotationNo,QuotationStatus FROM Quotations
WHERE Quotations.CustomerNo IN(
SELECT CustomerNo FROM Customers
WHERE Customers.CustomerState='销售机会');--要求查询结果的所有列都在同一张表中才能与多表联结互相转化

>)ENGINE=InnoDB    //设置表的贮存引擎,寻平常用InnoDB和MyISAM;InnoDB可信赖,协管事人业;MyISAM高效不扶持全文字笔迹查验索

表别名

>DEFAULT charset=utf8;  //设置默许的编码,幸免数据库普通话乱码

SELECT Q.QuotationNo,Q.QuotationStatus,C.Class
FROM Quotations Q,Customers C
WHERE C.CustomerState='销售机会'
AND Q.CustomerNo=C.CustomerNo;

SELECT QuotationNo,QuotationStatus,Class
FROM Quotations Q,Customers C
WHERE Q.QuotationStatus='处理中'
AND Q.CustomerNo=C.CustomerNo
AND C.CustomerState='销售机会';

比方有法规的创办数据表还足以应用  >CREATE TABLE IF NOT EXISTS
tb_name(……..

自联结

2、复制表:

SELECT C1.CustomerNo,C1.Class,C1.CustomerState
FROM Customers C1,Customers C2
WHERE C2.CustomerNo='CTM002'
AND C1.Class=C2.Class;--列出所有和CTM002的Class一样的客户

>CREATE TABLE tb_name2 SELECT * FROM tb_name;

将方面包车型大巴自联结语句调换到子查询语句

仍然局部复制:

SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE Class=(
SELECT Class FROM Customers
WHERE CustomerNo='CTM002'
);

>CREATE TABLE tb_name2 SELECT id,name FROM tb_name;

组合查询UNION和UNION ALL

3、成立有的时候表:

SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE Class='C'
UNION
SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE CustomerState='销售机会'---重复记录不显示

SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE Class='C'
UNION ALL
SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE CustomerState='销售机会'
ORDER BY 1,2;--重复记录显示

>CREATE TEMPORARY TABLE tb_name(这里和创办普通表同样);

探究在select第11中学存在而在select第22中学海市蜃楼的行

4、查看数据库中可用的表:

SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE Class='C'
EXCEPT
SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE CustomerState='销售机会'
ORDER BY 1,2;

>SHOW TABLES;

寻觅在多少个select语句中都设有的行

5、查看表的组织:

SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE Class='C'
INTERSECT
SELECT CustomerNo,Class,CustomerState
FROM Customers
WHERE CustomerState='销售机会'
ORDER BY 1,2;

>DESCRIBE tb_name;

插入一条数据INSERT INTO

也得以利用:

INSERT INTO Customers(cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email
)
VALUES('2018062501',
'AMY',
'北仑红联渡口路29号',
'宁波',
'OENW',
'28193',
'China',
NULL,
'277816@qq.com'
);
SELECT * FROM Customers;

>SHOW COLUMNS in tb_name;     //from也可以

INSERT INTO 的新用法:插入检索出的数据

6、删除表:

INSERT INTO CustNew(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email
)
SELECT* FROM Customers;


INSERT INTO CustNew(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email
)
SELECT* FROM Customers;

>DROP [ TEMPORARY ] TABLE [ IF EXISTS ] tb_name[
,tb_name2…….];

利用INSERT SELECT一遍插入多行

实例:

INSERT INTO CustNew(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email
)
SELECT* FROM Customers--不管SELECT出多少行都会被插入
WHERE NOT cust_id='2018062501';--排除掉已插入的行,不然会提示主键重复,语句结束
SELECT* FROM CustNew;

>DROP TABLE IF EXISTS tb_name;

电动创立多少个新表并完全复制另三个表的数码

7、表重命名:

SELECT* INTO CustCopy
FROM Customers;--这条语句自动创建CustCopy表并将Customers表中的数据完全复制并填充过去

>RENAME TABLE name_old TO name_new;

更新表中数据

还足以运用:

UPDATE CustCopy
SET cust_email='chenlili@intersky.com.cn',
cust_city='广西',
cust_name='陈莉莉'
WHERE cust_id='2018062503';
SELECT *FROM CustCopy;

>ALTER TABLE name_old RENAME name_new;

用表1的数额更新表2的多少

三、修改表:

ALTER TABLE CustNew ADD te VARCHAR(20);--在CustNew表中新建te列
UPDATE CustNew SET CustNew.te=CustCopy.cust_name
FROM CustCopy,CustNew
WHERE CustNew.cust_id=CustCopy.cust_id;--用CustCopy表中的cust_name列值更新CustNew表中的te列,条件是两表cust_id相等

1、改换表结构:

除去某些列的值能够将它设置为NULL

>ALTER TABLE tb_name ADD[CHANGE,RENAME,DROP] …要更动的内容…

UPDATE CustCopy
SET cust_address=NULL
WHERE cust_id='2018062502';
SELECT * FROM CustCopy;

实例:

删除表的某一行

>ALTER TABLE tb_name ADD COLUMN address varchar(80) NOT NULL;

DELETE FROM CustCopy
WHERE cust_id='2018062504'

>ALTER TABLE tb_name DROP address;

TRUNCATE
TABLE删除表

>ALTER TABLE tb_name CHANGE score score SMALLINT(4) NOT NULL;

动用TRUNCATE
TABLE能够快捷删除表中的兼具记录,並且无日志记录。与DELETE比较,速度更加快,使用的系统能源和事情日志财富越来越少。 使用DELETE语句,系统三次一行地管理要删减的表中的记录,并在事务管理日志中著录相关删除操作。 使用TRUNCATE
TABLE语句二回性实现删除与表有关的装有数据页的操作,且不创新事务管理日志,无法用ROLLBACK回滚。

四、插入数据:

TRUNCATE TABLE a;--删除表a中的所有数据

1、插入数据:

 

>INSERT INTO
tb_name(id,name,score)VALUES(NULL,’张三’,140),(NULL,’张四’,178),(NULL,’张五’,134);

创建表

此处的插入多条数据直接在后面加上逗号,直接写入插入的数据就能够;主键id是自增的列,可以不用写。

CREATE TABLE Products(
prod_id CHAR(10) NOT NULL,
vend_id CHAR(10) NOT NULL,
prod_name CHAR(254) NOT NULL,
prod_price DECIMAL(8,2) NOT NULL,
prod_desc VARCHAR(1000) NULL
);

CREATE TABLE Orders(
order_num INTEGER NOT NULL,
order_date DATETIME NOT NULL,
cust_id CHAR(10) NOT NULL
);

CREATE TABLE Vendors(
vend_id CHAR(10) NOT NULL,
vend_name CHAR(50) NOT NULL,
vend_address CHAR(50),
vend_city CHAR(50),
vend_state CHAR(5),
vend_zip CHAR(10),
vend_country CHAR(50)
);--不填写NULL和NOT NULL时默认为NULL

2、插入检索出来的多寡:

新建表并内定默许值DEFAULT

>INSERT INTO tb_name(name,score) SELECT name,score FROM tb_name2;

CREATE TABLE OrderItems(
order_num INTEGER NOT NULL,
order_item INTEGER NOT NULL,
prod_id CHAR(10) NOT NULL,
quantity INTEGER NOT NULL DEFAULT 1,
item_price DECIMAL(8,2) NOT NULL
);

五、更新数据:

更新表ALTER TABLE

1、钦定更新数据:

ALTER TABLE Vendors
ADD vend_phone CHAR(20);
SELECT * FROM Vendors;

ALTER TABLE Vendors
DROP COLUMN vend_phone;

ALTER TABLE Vendors
ADD PRIMARY KEY(vend_id);--给vend_id设置主键

>UPDATE tb_name SET score=189 WHERE id=2;

除去整张表及其表结构

>UPDATE tablename SET columnName=NewValue [ WHERE condition ]

DROP TABLE CustNew;

六、删除数据:

–重命名表

1、删除数据:

EXEC sp_rename 'Orders','testi21';
EXEC sp_rename 'testi21','Orders';

SELECT *FROM Orders;
GO;

>DELETE FROM tb_name WHERE id=3;

创设视图CREATE VIEW view_name AS…

七、条件决定:

CREATE VIEW ProductCustomers AS
SELECT cust_name,cust_contact,prod_id
FROM Customers,Orders,OrderItems
WHERE Customers.cust_id=Orders.cust_id
AND Orders.order_num=OrderItems.order_num;
GO;

SELECT * FROM ProductCustomers;

1、WHERE 语句:

除去视图

>SELECT * FROM tb_name WHERE id=3;

SELECT * FROM ProductCustomers
WHERE prod_id='0001';
DROP VIEW ProductCustomers;

2、HAVING 语句:

储存进度(类似自定义函数)

>SELECT * FROM tb_name GROUP BY score HAVING count(*)>2

SELECT *FROM Customers;
--输出Customers表中所有cust_contact为空的用户个数,利用存储过程结果应该为2;
GO;

CREATE PROCEDURE CusCount
@custc INTEGER OUT--带输出参数的存储过程
AS
SELECT @custc=COUNT(*) FROM Customers
WHERE cust_contact IS NULL;
RETURN @custc;
GO;

3、相关规范调节符:

新建无参数的积攒进程

=、>、<、<>、IN(1,2,3……)、BETWEEN a AND b、NOT

CREATE PROCEDURE MailingListCount AS
DECLARE @cnt INTEGER
SELECT @cnt=COUNT(*) FROM Customers
WHERE NOT cust_contact IS NULL;
RETURN @cnt;
GO;

AND 、OR

调用带输出参数的积存进度

Linke()用法中      %  为协作大肆、  _  相配一个字符(能够是汉字)

DECLARE @tt INTEGER
EXEC CusCount @tt OUTPUT;
SELECT @tt AS Ccount;

IS NULL 空值检验

调用无参数的囤积进程

八、MySQL的正则表明式:

DECLARE @ReturnValue INT
EXEC @ReturnValue=MailingListCount;
SELECT @ReturnValue AS Ccount;
GO

1、Mysql扶持REGEXP的正则表达式:

事务管理TRANSACTION

>SELECT * FROM tb_name WHERE name REGEXP ‘^[A-D]’  //寻找以A-D
为初阶的name

BEGIN TRANSACTION
DELETE FROM Orders;
ROLLBACK TRANSACTION;
GO;

/*
SELECT *FROM Orders;
INSERT INTO Orders VALUES(
'2819','2018-06-25 00:00:00.000','2018062501');
INSERT INTO Orders VALUES(
'2817','2018-06-25 00:00:00.000','2018062502');
INSERT INTO Orders VALUES(
'2818','2018-06-25 00:00:00.000','2018062503');*/

2、特殊字符要求转义。

事务管理,COMMIT显式提交

九、MySQL的一部分函数:

BEGIN TRANSACTION
DELETE FROM Orders WHERE cust_id='2018062501'
DELETE FROM Customers WHERE cust_id='2018062501' 
COMMIT TRANSACTION--这两行语句要不一起提交,要不全部不提交,不存在部分执行完成。

1、字符串链接——CONCAT()

加上保留点SAVE TRANSACTION和回滚至保留点ROLLBACK TRANSACTION

>SELECT CONCAT(name,’=>’,score) FROM tb_name

BEGIN TRANSACTION
SELECT *FROM Orders;
DELETE FROM Orders;
INSERT INTO Orders VALUES(
'2819','2018-06-25 00:00:00.000','2018062501');
SAVE TRANSACTION insert1;
INSERT INTO Orders VALUES(
'2817','2018-06-25 00:00:00.000','2018062502');
SAVE TRANSACTION insert2;
INSERT INTO Orders VALUES(
'2818','2018-06-25 00:00:00.000','2018062503');
SAVE TRANSACTION insert3;
ROLLBACK TRANSACTION insert2;--回滚至保留点insert2

2、数学函数:

游标的概念和行使

AVG、SUM、MAX、MIN、COUNT;

1 DECLARE CustCursor SCROLL CURSOR
2 FOR
3 SELECT cust_id FROM Customers
4 WHERE cust_contact IS NULL;--定义游标CustCursor
5 OPEN CustCursor;--打开游标

3、文本管理函数:

如何运用一个已开发的游标

TRIM、LOCATE、UPPER、LOWER、SUBSTRING

DECLARE @cursor CHAR(10);--定义参数cursor
FETCH FIRST FROM CustCursor INTO @cursor;--将游标的值传入该参数
SELECT @cursor AS Cursortest;--将参数输出并取别名为Cursortest

4、运算符:

剔除游标

+、-、*、

1 CLOSE CustCursor;
2 DEALLOCATE CustCursor;--释放游标占用的资源

5、时间函数:

游标的轮转实例

DATE()、CURTIME()、DAY()、YEAR()、NOW()…..

DECLARE CustCursor SCROLL CURSOR
FOR
SELECT cust_id FROM Customers
WHERE cust_contact IS NULL;
OPEN CustCursor;
DECLARE @cursor1 CHAR(10);
FETCH NEXT FROM CustCursor INTO @cursor1
WHILE (@@FETCH_STATUS=0)--游标的循环
BEGIN
FETCH NEXT FROM CustCursor INTO @cursor1--将游标指向下一个值
END
SELECT @cursor1 AS TT;

十、分组查询:

闭馆游标并释放能源

1、分组查询能够遵循钦命的列举行分组:

CLOSE CustCursor;
DEALLOCATE CustCursor;

>SELECT COUNT(*) FROM tb_name GROUP BY score HAVING COUNT(*)>1;

主键与外键

2、条件使用Having;

ALTER TABLE Products
ADD PRIMARY KEY(prod_id);--用ALTER语句添加主键

3、ORDER BY 排序:

用ALTEEvoque设置外键

O奥迪Q3DE凯雷德 BY DESC|ASC    =>按数量的降序和升序排列

ALTER TABLE Orders
ALTER COLUMN cust_id NCHAR(10);--两个表数据类型不同设置外键会报错,因此先更改外键字段的数据类型

ALTER TABLE Orders
ADD CONSTRAINT FK_ord--将Orders.cust_id用CONSTRAINT关键字设置唯一约束
FOREIGN KEY(cust_id)
REFERENCES Customers(cust_id)
GO

十一、UNION法则——能够奉行五个语句(能够去除重复行)

用ALTEKuga语句设置独一约束

十二、全文字笔迹核算索——MATCH和AGAINST

ALTER TABLE Vendors
ADD UNIQUE(Vend_id);

1、SELECT MATCH(note_text)AGAINST(‘PICASO’) FROM tb_name;

用ALTE哈弗语句设置检查约束

2、InnoDB引擎不帮衬全文字笔迹核准索,MyISAM能够;

ALTER TABLE Products
ADD CHECK(prod_price>0);

十三、视图

增多索引,系统基于目录飞速查询数据

1、创制视图

CREATE INDEX prod_name_int
ON Products(prod_name);
SELECT *FROM Products WHERE prod_name='莫匹罗星软膏';
GO;

>CREATE VIEW name AS SELECT * FROM tb_name WHERE ~~ ORDER BY ~~;

开创触发器

2、视图的特殊效用:

CREATE TRIGGER cust_state
ON Customers
FOR INSERT,UPDATE
AS
UPDATE Customers
SET cust_state=UPPER(cust_state)
WHERE Customers.cust_id=(SELECT cust_id from inserted);--当Customers.cust_state发生INSERT,UPDATE操作时,触发器将自动把cust_state字段内容从小写变成大写

a、简化表之间的联合(把联结写在select中);

触发器测量检验

b、重新格式化输出检索的多少(T哈弗IM,CONCAT等函数);

INSERT INTO Customers(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_email
)VALUES(
'2018062506',
'Lily',
'世纪大道333号',
'北京',
'ienwoho',
'783428@qq.com'
);
SELECT *FROM Customers;

必赢365net手机版,c、过滤不想要的数额(select部分)

 

d、使用视图计算字段值,如聚焦那样的值。

十四、使用存款和储蓄进度:

私家精通,存款和储蓄进程正是二个自定义函数,有局地变量参数,可传唱参数,能够再次来到值,可是那语法够死板的~~~

1、成立存款和储蓄进度:

>CREATE PROCEDURE pro(

>IN num INT,OUT total INT)

>BEGIN

>SELECT SUM(score) INTO total FROM tb_name WHERE id=num;

>END;

***此间的  IN
(传递一个值给存款和储蓄进程),OUT(从存款和储蓄进度传出二个值),INOUT(对存款和储蓄进程传入、传出),INTO(保存变量)

2、调用存款和储蓄进度:

>CALL
pro(13,@total)      //这里的存放过程五个变量,八个是IN叁个是OUT,这里的OUT也是急需写上的,不写会出错

>SELECT @total         //这里就能够看看结果了;

3、存款和储蓄进度的别样操作:

>SHOW PROCEDURE STATUS;      //突显当期的存放进程

>DROP PROCEDURE pro;         //删除钦命期存款款和储蓄进程

十五、使用游标:

对那么些明白不是很懂,朋友多多引导哦~~~

1、游标的操作

>CREATE PROCEDURE pro()

>BEGIN

>DECLARE ordername CURSOR FOR

>SELECT order_num FROM orders;

>END;

>OPEN ordername;    //张开游标

>CLOSE ordername;    //关闭游标

十六、触发器:

触发器是指在进展某项钦定操作时,触发触发器内钦定的操作;

1、帮忙触发器的语句有DELETE、INSERT、UPDATE,其余均不协助

2、创制触发器:

>CREATE TRIGGER trig AFTER INSERT ON ORDERS FOR EACH ROW SELECT
NEW.orser_name;

>INSERT语句,触发语句,再次回到两个值

3、删除触发器

>DROP TRIGGER trig;

十七、语法整理:

1、ALTER TABLE(修改表)

ALTER TABLE table_name

(  ADD    column  datatype    [ NULL | NOT NULL ]  [
CONSTRAINTS ]

CHANGE  column   datatype   COLUMNS  [ NULL | NOT NULL ]  
[ CONSTRAINTS ]

DROP    column,

。。。。

)

2、COMMIT(处监护人务)

>COMMIT;

3、CREATE INDEX(在三个或多个列上创设索引)

CREATE INDEX index_name ON tb_name (column [ ASC | DESC ] ,
…….);

4、CREATE PROCEDURE (创设存款和储蓄进度)

CREATE PROCEDURE pro([ parameters ])

BEGIN

……..

END

5、CREATE TABLE(创建表)

CREATE TABLE tb_name(

column_name  datetype  [ NULL | NOT NULL ]   [ condtraints] 
,

column_name  datetype  [ NULL | NOT NULL ]   [ condtraints] 
,

…….

PRIMARY KEY( column_name )

)ENGINE=[  InnoDB | MyiSAM ]DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

6、CREATE USEEscort(创造客户)

CREATE USER user_name [ @hostname ] [ IDENTIFIED BY [ PASSWORD ]
‘pass_word’ ];

7、CREATE VIEW (在叁个或多少个表上创建视图)

CREATE [ OR REPLACE ] VIEW view_name AS SELECT。。。。。。

8、DELETE (从表中删除一行或多行)

DELETE FROM table_name [WHERE ……]

9、DROP(恒久删除数据库及对象,如视图、索引等)

DROP DATEBASE | INDEX | PROCEDURE | TABLE | TRIGGER | USER | VIEW  name

10、INSERT (给表增加行)

INSERT INTO tb_name [ ( columns,…… ) ] 
VALUES(value1,…………);

使用SELECT值插入:

INSERT INTO tb_name [ ( columns,…… ) ]

SELECT columns , …….  FROM tb_name [ WHERE …… ] ;

11、ROLLBACK(打消三个事务管理块)

ROLLBACK [  TO  savapointname  ];

12、SAVEPOINT(为ROLLBACK设置保留点)

SAVEPOINT sp1;

13、SELECT (检索数据,展现音讯)

SELECT column_name,…..FROM tb_name  [ WHERE ]  [ UNION ]    [
RROUP BY ]  [ HAVING ]  [ ORDER BY ]

14、START TRANSACTION (三个新的事务处理块的最早)

START TRANSACTION

15、UPDATE(更新八个表中的一行或多行)

UPDATE tb_name SET column=value,……[ where ]

Leave a Comment.