pubs
データベースで、著者、タイトルのリストを作ろうと思うと、N対Nの関係になっているので、次の図のように3つのテーブルにアクセスする必要があります。このような場合にはビューを使うと簡単になります。

ビューの作成例USE pubs
GO
IF EXISTS(SELECT name from sysobjects where name = 'MyTitleView')
BEGIN
print 'exists'
print 'drop View'
Drop View MyTitleView
END
GO
CREATE VIEW MyTitleView (title, au_lname, au_fname)
AS
SELECT title, au_lname, au_fname
FROM dbo.authors INNER JOIN dbo.titleauthor ON authors.au_id=titleauthor.au_id
INNER JOIN titles ON titles.title_id=titleauthor.title_id
GO
これにより
SELECT * from MyTitleView
テーブルを参照するのと同様に参照できます。
