mysql> create view db_users.v_idlogin as select userid, last_login as login_date from tb_users where birth < '1980-1-1'; Query OK, 0 rows affected (0.04 sec) mysql> show tables; +--------------------+ | Tables_in_db_users | +--------------------+ | tb_users | | v_idlogin | +--------------------+ 2 rows in set (0.00 sec) mysql> select * from v_idlogin; +--------+------------+ | userid | login_date | +--------+------------+ | 10003 | 2014-09-20 | | 10004 | 2015-02-10 | +--------+------------+ 2 rows in set (0.02 sec)
mysql> drop view if exists v_idlogin; Query OK, 0 rows affected (0.00 sec) mysql> show tables; +--------------------+ | Tables_in_db_users | +--------------------+ | tb_users | +--------------------+ 1 row in set (0.00 sec)
mysql> mysql> delimiter $ mysql> create procedure get_one_user( -> in id int) -> begin -> select * from tb_users where userid>id; -> end; -> $ Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
mysql> call get_one_user(10005) -> ; +--------+----------+------------+------------+ | userid | username | birth | last_login | +--------+----------+------------+------------+ | 10007 | Hamilton | 1988-07-07 | 2014-11-16 | | 10008 | Johnson | 1986-06-07 | 2015-01-23 | | 10009 | James | 1989-08-17 | 2013-12-23 | | 10010 | james | 1984-12-30 | 2014-12-23 | | 10011 | Gay | 1987-02-03 | 2014-12-23 | | 10012 | Kaman | 1981-04-04 | 2010-01-13 | | 10006 | Wade | 1982-03-04 | 2012-05-19 | +--------+----------+------------+------------+ 7 rows in set (0.04 sec) Query OK, 0 rows affected (0.04 sec)
mysql> select * from tb_users; +--------+----------+------------+------------+ | userid | username | birth | last_login | +--------+----------+------------+------------+ | 10000 | Allen | 1981-01-01 | 2014-02-02 | | 10001 | Ben | 1982-04-02 | 2014-04-30 | | 10002 | Curry | 1985-08-12 | 2014-01-17 | | 10003 | Davis | 1978-07-12 | 2014-09-20 | | 10004 | Ellis | 1979-09-02 | 2015-02-10 | | 10005 | Faried | 1984-02-05 | 2014-12-01 | | 10007 | Hamilton | 1988-07-07 | 2014-11-16 | | 10008 | Johnson | 1986-06-07 | 2015-01-23 | | 10009 | Jackson | 1989-08-17 | 2013-12-23 | | 10010 | James | 1984-12-30 | 2014-12-23 | | 10011 | Gay | 1987-02-03 | 2014-12-23 | | 10012 | Kaman | 1981-04-04 | 2010-01-13 | | 10006 | Wade | 1982-03-04 | 2012-05-19 | +--------+----------+------------+------------+ 13 rows in set (0.00 sec) mysql> create unique index idx_name on tb_users(username(5)); Query OK, 13 rows affected (0.13 sec) Records: 13 Duplicates: 0 Warnings: 0 mysql>
原文地址:http://blog.csdn.net/shallnet/article/details/46483737