标签:mysql 存储过程 navicat for mysql
用可视化工具SQLyog
可参考:http://www.cnblogs.com/gaizai/p/3237907.html
区别 | MSSQL | MySQL |
注释 | 单行注释:-- 段落注释:/*abc*/ | 单行注释://或者#或者-- (多一个空格) 多行注释:/*abc*/ |
存储过程 | CREATE PROC test1(@s BIGINT) BEGIN ... END | CREATE PROCEDURE test1(IN s BIGINT) BEGIN ... END; |
修改列 | alter table 表 alter column 列 类型 | ALTER TABLE 表 CHANGE 旧列名 新列名 类型; |
删除主键 | alter table 表 drop 主键名
| alter table 表 drop primary key; |
按F6(工具-命令列界面)进入命令列
或者打开查询窗口
创建表:
mysql> create table t1(id bigint,name nvarchar(200));
Query OK, 0 rows affected
修改表:
mysql> alter table t1 add addtime datetime;
mysql> alter table t1 drop column addtime;
mysql> alter table t1 change name score int;
查看表结构:
mysql> desc t1;
mysql> show columns from t1;
mysql> show create table t1;
删除表:
mysql> drop table t1;
新增索引:mysql> create index xID on t1(id);
mysql> alter table t1 add index xID (id);
删除索引:mysql> drop index xID on t1;
mysql> alter table t1 drop index xID;
查看索引:mysql> show index from t1;
重建索引:mysql> repair table t1 quick;
索引统计:右键-对象信息
添加主键:mysql> alter table t1 add primary key(id);
删除主键:mysql> alter table t1 drop primary key;
添加外键:
mysql> alter table testtag add constraint fk_test foreign key (ClassID) references testclass(ID);
删除外键:mysql> ALTER TABLE testtag DROP FOREIGN KEY `fk_test`;
新增数据:
mysql> insert into t1(id,name)
-> select 123456,‘ssssk‘;
mysql> insert into t1
-> values(111111,‘asd‘);
mysql> insert into t1
-> select 111112,‘abc‘ union all
-> select 111113,‘abcd‘;
查询数据:
mysql> select * from t1 where id=123456;
mysql> SELECT ID FROM TEST ORDER BY ID LIMIT 0,3;//显示前三行
mysql> select distinct id from testclass;
mysql> select addy,count(1)as digit from test group by addy order by count(1);
更新数据:
mysql> update t1 set name=‘ssss‘ where id=123456;
删除数据:
mysql> delete from t1 where id=111111;
(1)输出参数:
mysql> create procedure test(out s int)
-> begin
-> select count(1)into s from tabletest;
-> end;
调用存储过程
mysql> call test(@a);
Query OK, 1 row affected
mysql> select @a;
+---------+
| @a |
+---------+
| 1080227 |
+---------+
1 row in set
(2)输入参数:
mysql> CREATE PROCEDURE test1(IN s BIGINT)
-> BEGIN
-> SELECT ID FROM tabletest WHERE ID=s;
-> END;
Query OK, 0 rows affected
mysql> CALL test1(610815855784);
+--------------+
| ID |
+--------------+
| 610815855784 |
+--------------+
1 row in set
Query OK, 0 rows affected
(3)表连接:
mysql> CREATE PROCEDURE test2(IN s BIGINT)
-> BEGIN
-> SELECT a.ID,b.ID,c.ID from testtag a left join testontag b on a.ID=b.tagid left join test c on b.questionid=c.ID WHERE c.ID=s;
-> END;
Query OK, 0 rows affected
mysql> call test2(24);
| 24 | 819070732577611835 | NULL |
| 24 | 821895448838848274 | NULL |
| 24 | 822129946375574167 | NULL |
| 24 | 822137865163194930 | NULL |
+----+--------------------+------+
17550 rows in set
本文出自 “sukun” 博客,请务必保留此出处http://sukunwu.blog.51cto.com/10453116/1687695
标签:mysql 存储过程 navicat for mysql
原文地址:http://sukunwu.blog.51cto.com/10453116/1687695