問題描述
我必須從 MS SQL Server 數(shù)據(jù)庫中的多個(gè)表創(chuàng)建視圖,但我無法獲得相同的正確語法.
I have to create a view from more than one table in an MS SQL Server database, but I am not able to get the correct syntax for the same.
推薦答案
您必須提供有關(guān)如何從多個(gè)表中返回?cái)?shù)據(jù)的更多信息.通常您使用 JOIN:
You'll have to provide more information about how you are looking to return data from more than one table. Typically you use JOINs:
CREATE VIEW your_view_vw AS
SELECT *
FROM TABLE_A a
JOIN TABLE_B b ON b.pk = a.fk
...其中 fk
代表外鍵",而 pk
代表主鍵"——假設(shè)這些約束已經(jīng)到位.也許您需要改用交叉連接?這是一個(gè) JOIN 的出色視覺表示.
...where fk
stands for "Foreign Key", and pk
stands for "Primary Key" - assuming these constraints are in place. Maybe you need to use a Cross join instead? Here's a great visual representation of JOINs visually.
參考:
- 創(chuàng)建視圖
這篇關(guān)于如何從多個(gè)表創(chuàng)建視圖?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!