标签:prim ack 技术分享 cut tab efault 查询 substr 名称
mysql> help create index Name: ‘CREATE INDEX‘ Description: Syntax: CREATE [ONLINE|OFFLINE] [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name [index_type] ON tbl_name (index_col_name,...) [index_option] ..
mysql> select * from vc; +------+------+ | v | c | +------+------+ | AB | AB | +------+------+ 1 row in set (0.00 sec) mysql> create index idx_v on vc(v); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table vc add KEY idx_c (c); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show index from vc; +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | vc | 1 | idx_v | 1 | v | A | 1 | NULL | NULL | YES | BTREE | | | | vc | 1 | idx_c | 1 | c | A | 1 | NULL | NULL | YES | BTREE | | | +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 2 rows in set (0.00 sec) mysql> show create table vc; +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | vc | CREATE TABLE `vc` ( `v` varchar(5) DEFAULT NULL, `c` char(5) DEFAULT NULL, KEY `idx_v` (`v`), KEY `idx_c` (`c`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> alter table order add primary key (id) #实际上是给主键id增加了一个索引,而这个索引又是唯一的所以就这个索引就变成了唯一约束
mysql>alter table order add unique key idx_uk_orderid(id)
mysql > alter table order add CONSTRAINT constarint_uid FOREIGN KEY (userid) REFERENCES user(userid)
mysql > alter table order add CONSTRAINT constarint_uid FOREIGN KEY (userid) REFERENCES user(userid) on delete restrict on update cascade;
mysql> select * from c_A; +----+------+ | id | age | +----+------+ | 1 | 22 | | 2 | 3 | | 3 | 4 | +----+------+ 3 rows in set (0.00 sec) mysql> select * from c_B; +----+------+ | id | age | +----+------+ | 1 | 2 | | 2 | 33 | | 3 | 4 | +----+------+ 3 rows in set (0.00 sec) mysql> update c_B set id=11 where age = 2; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from c_B; +----+------+ | id | age | +----+------+ | 2 | 33 | | 3 | 4 | | 11 | 2 | +----+------+ 3 rows in set (0.00 sec) mysql> select * from c_A; +----+------+ | id | age | +----+------+ | 2 | 3 | | 3 | 4 | | 11 | 22 | +----+------+ 3 rows in set (0.00 sec)
on delete cascade | insert | update | delete |
parent | yes | 只能更改子表中约束字段没有的值 | yes |
child | 只能插入父表中约束字段有的值; | 只能更改父表中约束字段没有的值 | yes |
on update cascade | insert | update | delete |
parent | yes | yes | 只能删子表中约束字段没有的值; |
child | 只能插入父表中约束字段有的值; | 只能更新父表中约束字段没有的值 | yes |
mysql> alter table order drop FOREIGN KEY constarint_uid;
mysql > create view order_view as select * from order where status = 1
mysql> CREATE TABLE t (qty INT, price INT); mysql> INSERT INTO t VALUES(3, 50); mysql> CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t; mysql> SELECT * FROM v; +------+-------+-------+ | qty | price | value | +------+-------+-------+ | 3 | 50 | 150 | +------+-------+-------+
CREATE [DEFINER = {user | CURRENT_USER}] -- 定义执行着的权限 TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW --涉及的每一行都会执行trigger_body trigger_body t trigger_time:{BEFORE | AFTER} trigger_event:{INSERT | UPDATE | DELETE}
CREATE [ DEFINER = { user | CURRENT_USER } ] --定义执行着的权限 PROCEDURE sp_name ( [ proc_parameter[ ,... ] ] ) [ characteristic .. ] routine_body proc_parameter: [ IN | OUT | INOUT] param_name type type: Any valid MySQL data type
mysql> show PROCEDURE STATUS ;
mysql> SHOW TRIGGER STATUS ;
mysql> set @total = 5; mysql> set @res = 0;
mysql> call proc_test1(@total,@res);
mysql> select @res
DROP {PROCEDURE | FUNCTION} [IF EXISTS] sp_name
mysql> select func_test1(4);
标签:prim ack 技术分享 cut tab efault 查询 substr 名称
原文地址:http://www.cnblogs.com/fengli9998/p/6938419.html