xml地图|网站地图|网站标签 [设为首页] [加入收藏]
当前位置: www8029com > 澳门新葡8522最新网站 > 正文

SQL必知必会,mysql常用语法操作

时间:2019-11-01 15:41来源:澳门新葡8522最新网站
select CustomerNo from dbo.Customers; 大器晚成、客商管理: 通配符的行使 1、新建顾客: select *from dbo.Customers;select CustomerNo from dbo.Customerswhere CustomerNo LIKE'[AQ]%';--[]表示中括号中内容任取其一,
select CustomerNo from dbo.Customers;

大器晚成、客商管理:

通配符的行使

1、新建顾客:

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

>CREATE USER name IDENTIFIED BY 'ssapdrow';

拼接字段

2、修正密码:

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

>SET PASSWORD FOR name=PASSWORD('fdddfd');

文本管理函数的运用RT奥迪Q3IM和LTOdysseyIM

3、权限管理

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

>SHOW GRANTS FOXC60 name;    //查看name顾客权限
>GRANT SELECT ON db_name.* TO name;    //给name用户db_name数据库的具备权力
>REVOKE SELECT ON db_name.* TO name;    //GRANT的反操作,去除权限;

排序O奥迪Q3DE中华V BY并以列号指代某一列

二、数据库操作: 

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

1、查看数据库:

NOT操作符,检索除某生龙活虎项之外的具备数据

>SHOW DATABASES;

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

2、创立数据库:

IN操作符,检索在有个别条件约束内的数码

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

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

3、使用数据库:

文本管理函数UPPELacrosse和LOWE奥迪Q7的施用,将列值转换为题写可能转变到小写

>USE db_name;

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%'

4、删除数据库:

时间管理函数DATEPART的利用,取时间值中的某风度翩翩项数据

>DROP DATABASE db_name;

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

三、创建表:

会集函数AVG,COUNT,MAX,MIN,SUMD的行使

1、创建表:

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

>CREATE TABLE table_name(
>id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,    //id值,无符号、非空、依次增加——唯生龙活虎性,可做主键。
>name VARCHAR(60) NOT NULL
>score TINYINT UNSIGNED NOT NULL DEFAULT 0,    //设置暗中同意列值
>PRIMARY KEY(id)
>)ENGINE=InnoDB    //设置表的存放引擎,平时常用InnoDB和MyISAM;InnoDB可信赖,扶植职业;MyISAM高效不扶助全文字笔迹查证索
>DEFAULT charset=utf8;  //设置暗许的编码,防止数据库普通话乱码

分组函数GROUP BY

设若有标准化的开创数据表还足以接纳

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

  >CREATE TABLE IF NOT EXISTS tb_name(........

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

2、复制表:

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

>CREATE TABLE tb_name2 SELECT * FROM tb_name;

内联合,联结三个表的询问语句

大概有个别复制:

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;

>CREATE TABLE tb_name2 SELECT id,name FROM tb_name;

将多表联结转变为子查询语句

3、创立有的时候表:

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='销售机会');--要求查询结果的所有列都在同一张表中才能与多表联结互相转化

>CREATE TEMPORARY TABLE tb_name(这里和开创普通表相符);

表别名

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

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='销售机会';

>SHOW TABLES;

自联结

5、查看表的构造:

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

>DESCRIBE tb_name;

将下面的自联结语句转变到子查询语句

也得以动用:

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

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

重新整合查询UNION和UNION ALL

6、删除表:

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;--重复记录显示

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

查找在select第11中学存在而在select第22中学不设有的行

实例:

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

>DROP TABLE IF EXISTS tb_name;

寻找在八个select语句中都存在的行

7、表重命名:

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

>RENAME TABLE name_old TO name_new;

插入一条数据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;

>ALTER TABLE name_old RENAME name_new;

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

四、修改表:

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;

1、改革表结构:

采纳INSERT SELECT三遍插入多行

>ALTER TABLE tb_name ADD[CHANGE,RENAME,DROP] ...要校订的内容...

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;

实例:

自动成立一个新表并完全复制另八个表的数额

>ALTER TABLE tb_name ADD COLUMN address varchar(80) NOT NULL;
>ALTER TABLE tb_name DROP address;
>ALTER TABLE tb_name CHANGE score score SMALLINT(4) NOT NULL;

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

五、插入数据:

更新表中数据

1、插入数据:

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

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

用表1的多少更新表2的多寡

这边的插入多条数据直接在前面加上逗号,直接写入插入的数码就能够;主键id是自增的列,能够不用写。

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相等

2、插入检索出来的数据:

除去有个别列的值能够将它设置为NULL

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

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

六、更新数据:

删除表的某意气风发行

1、钦定更新数据:

DELETE FROM CustCopy
WHERE cust_id='2018062504'

>UPDATE tb_name SET score=189 WHERE id=2;
>UPDATE tablename SET columnName=NewValue [ WHERE condition ]

TRUNCATE TABLE删除表

七、删除数据:

接纳TRUNCATE TABLE能够急迅删除表中的兼具记录,并且无日志记录。与DELETE比较,速度越来越快,使用的系统能源和职业日志财富更加少。 使用DELETE语句,系统一遍意气风发行地拍卖要去除的表中的笔录,并在事务管理日志中记录相关删除操作。 使用TRUNCATE TABLE语句三次性实现删除与表有关的富有数据页的操作,且不更新事务管理日志,不能够用ROLLBACK回滚。

1、删除数据:

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

>DELETE FROM tb_name WHERE id=3;

 

八、条件决定:

创建表

1、WHERE 语句:

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

>SELECT * FROM tb_name WHERE id=3;

新建表并内定默许值DEFAULT

2、HAVING 语句:

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
);

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

更新表ALTER TABLE

3、相关标准调节符:

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设置主键

=、>、<、<>、IN(1,2,3......)、BETWEEN a AND b、NOT
AND 、OR
Like()用法中      %  为同盟自便、  _  相配一个字符(可以是汉字)
IS NULL 空值检查测验

剔除整张表及其表结构

九、MySQL的正则表明式:

DROP TABLE CustNew;

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

--重命名表

>SELECT * FROM tb_name WHERE name REGEXP '^[A-D]'   //寻觅以A-D 为起头的name

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

SELECT *FROM Orders;
GO;

2、特殊字符要求转义。

开创视图CREATE VIEW view_name AS...

十、MySQL的后生可畏对函数:

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、字符串链接——CONCAT()

删除视图

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

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

2、数学函数:

仓库储存进程(相符自定义函数)

AVG、SUM、MAX、MIN、COUNT;

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、文本管理函数:

新建无参数的累积进度

TRIM、LOCATE、UPPER、LOWER、SUBSTRING

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

4、运算符:

调用带输出参数的仓库储存进度

、-、*、

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

5、时间函数:

调用无参数的寄存过程

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

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

十风度翩翩、分组查询:

事务管理TRANSACTION

1、分组查询能够根据钦定的列进行分组:

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');*/

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

事务管理,COMMIT显式提交

2、条件使用Having;

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

3、ORDER BY 排序:

累积保留点SAVE TRANSACTION和回滚至保留点ROLLBACK TRANSACTION

OSportageDE卡宴 BY DESC|ASC    =>按数据的降序和升序排列

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

十五、UNION准绳——能够举办多个语句(能够去除重复行)

游标的概念和选用

十四、全文字笔迹核准索——MATCH和AGAINST

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

1、SELECT MATCH(note_text)AGAINST('PICASO') FROM tb_name;
2、InnoDB引擎不援救全文检索,MyISAM能够;

哪些接受多少个已开荒的游标

十四、视图

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

1、成立视图

除去游标

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

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

2、视图的特殊效用:

游标的滚动实例

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

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;

b、重新格式化输出检索的数额(TLacrosseIM,CONCAT等函数);

闭馆游标并释放财富

c、过滤不想要的数目(select部分)

CLOSE CustCursor;
DEALLOCATE CustCursor;

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

主键与外键

十九、使用存款和储蓄进程:

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

私家了然,存款和储蓄进程正是贰个自定义函数,有部分变量参数,可传唱参数,能够再次来到值,不过那语法够愚拙的~~~

用ALTE奔驰G级设置外键

1、创造存款和储蓄进度:

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

>CREATE PROCEDURE pro(
>IN num INT,OUT total INT)
>BEGIN
>SELECT SUM(score) INTO total FROM tb_name WHERE id=num;
>END;

用ALTE陆风X8语句设置唯风姿罗曼蒂克约束

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

ALTER TABLE Vendors
ADD UNIQUE(Vend_id);

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

用ALTELacrosse语句设置检查约束

>CALL pro(13,@total)      //这里的累积进程八个变量,叁个是IN四个是OUT,这里的OUT也是供给写上的,不写会出错
>SELECT @total         //这里就能够旁观结果了;

ALTER TABLE Products
ADD CHECK(prod_price>0);

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

增添索引,系统依照目录急迅查询数据

>SHOW PROCEDURE STATUS;      //展现当期的存放进程
>DROP PROCEDURE pro;         //删除钦赐期存款款和储蓄进程

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

十九、使用游标:

开创触发器

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

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字段内容从小写变成大写

1、游标的操作

触发器测量试验

>CREATE PROCEDURE pro()
>BEGIN
>DECLARE ordername CURSOR FOR
>SELECT order_num FROM orders;
>END;
>OPEN ordername;    //打开游标
>CLOSE ordername;    //关闭游标

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;

十七、触发器:

 

触发器是指在拓宽某项钦点操作时,触发触发器内内定的操作;

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 USE奥迪Q5(创立顾客)

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_澳门新葡8522最新网站,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 ]

编辑:澳门新葡8522最新网站 本文来源:SQL必知必会,mysql常用语法操作

关键词: www8029com