更改mySQL中的View以添加屬於另一個表的另一列

[英]Altering the View in mySQL to add another column belonging to another table


I have a database named dev and a view named employees_view (primary key - idEmployee). Now I want to add another (existing) column named Employee_Type (VARCHAR 45) belonging to another (existing) table Ref_Employee_Categories (primary key- idEmployee_Category) to my view - employees_view.

我有一個名為dev的數據庫和一個名為employees_view的視圖(主鍵 - idEmployee)。現在我想將屬於另一個(現有)表Ref_Employee_Categories(primary key-idEmployee_Category)的名為Employee_Type(VARCHAR 45)的另一個(現有)列添加到我的視圖 - employees_view。

I am not too good with databases so I need to know, how can I do this. All I know about altering views is : ALTER VIEW dev.employee_view ADD dev.Ref_Employee_Categories.Employee_Type varchar (45)

我對數據庫不是很好,所以我需要知道,我該怎么做。我對改變視圖的了解是:ALTER VIEW dev.employee_view ADD dev.Ref_Employee_Categories.Employee_Type varchar(45)

Is what I wrote above correct? If not what is the proper syntax of doing that?

我上面寫的是正確的嗎?如果不是這樣做的正確語法是什么?

1 个解决方案

#1


2  

noup, it's not correct, a view it's (like) just a easy way to make a query , for example.

noup,它不正確,一個視圖(例如)只是一種簡單的查詢方式。

if you have something like this:

如果你有這樣的事情:

select * from table_1 as t1 join table_2 as t2 on t1.id=t2.id join table_3 ....... join table_100 on t100.id=t99.id

select * from table_1 as t1 join table_2 as t2 on t1.id = t2.id join table_3 ....... join table_100 on t100.id = t99.id

you can resume all that query and make:

您可以恢復所有查詢並進行:

CREATE VIEW big_query AS select * from table_1 as t1 join table_2 as t2 on t1.id=t2.id join table_3 ....... join table_100 on t100.id=t99.id;

CREATE VIEW big_query AS select * from table_1 as t1 join table_2 as t2 on t1.id = t2.id join table_3 ....... join table_100 on t100.id = t99.id;

If you now make select * from big_query you will execute the 100's joins.

如果你現在從big_query中選擇*,你將執行100的連接。

If you want to change your View and add another column, you will have to write the query manually and after that create a VIEW

如果要更改View並添加其他列,則必須手動編寫查詢,然后創建VIEW

you can find more info here: http://dev.mysql.com/doc/refman/5.0/en/create-view.html

你可以在這里找到更多信息:http://dev.mysql.com/doc/refman/5.0/en/create-view.html


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/08/31/720e16247e3b927145b13eedfa2c2c31.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com