选择数据库
mysql> USE hr;
Database changed
mysql> CREATE VIEW my_v1 AS SELECT * FROM user_details;
Query OK, 0 rows affected (0.13 sec)
mysql> SELECT * FROM user; +----------+-----------+--------+ | userid | password | name | +----------+-----------+--------+ | scott123 | 123@sco | Scott | | ferp6734 | dloeiu@&3 | Palash | | diana094 | ku$j@23 | Diana | +----------+-----------+--------+ 3 rows in set (0.04 sec) mysql> CREATE VIEW my_v2 AS SELECT * FROM user; Query OK, 0 rows affected (0.05 sec)
mysql> SELECT * FROM my_v2; +----------+-----------+--------+ | userid | password | name | +----------+-----------+--------+ | scott123 | 123@sco | Scott | | ferp6734 | dloeiu@&3 | Palash | | diana094 | ku$j@23 | Diana | +----------+-----------+--------+ 3 rows in set (0.05 sec)
创建一个视图
mysql> CREATE VIEW my_v3 AS SELECT userid AS User_ID, password AS Password, name AS Name FROM user; Query OK, 0 rows affected (0.04 sec)
mysql> SELECT * FROM my_v3; +----------+-----------+--------+ | User_ID | Password | Name | +----------+-----------+--------+ | scott123 | 123@sco | Scott | | ferp6734 | dloeiu@&3 | Palash | | diana094 | ku$j@23 | Diana | +----------+-----------+--------+ 3 rows in set (0.04 sec)
转载请注明:谷谷点程序 » mysql视图的使用方法