1. 程式人生 > >mysql中的檢視建立和修改

mysql中的檢視建立和修改

1、建立檢視
CREATE 
VIEW `NewView`AS 
SELECT
`user`.USER_ID,
`user`.USER_NAME,
department.DEPT_ID,
department.DEPT_NAME
FROM
`user` ,
department
WHERE
`user`.DEPT_ID = department.DEPT_ID ;

2、修改檢視

ALTER 
ALGORITHM=UNDEFINED 
DEFINER=`root`@`127.0.0.1` 
SQL SECURITY DEFINER 
VIEW `dept_user` AS 
select `user`.`USER_ID` AS `USER_ID`,`user`.`USER_NAME` AS `USER_NAME`,`department`.`DEPT_ID` AS `DEPT_ID`,`department`.`DEPT_NAME` AS `DEPT_NAME`
from (`user` join `department`)
where (`user`.`DEPT_ID` = `department`.`DEPT_ID`)
ORDER BY
department.DEPT_NO ASC ;