Is it possible to write a database view that covers a one-to-many relationship?

So, Iโ€™m not necessarily saying that itโ€™s even a good idea if it was possible, since the presentation scheme would be extremely mutable, but is there a way to present has-many relationships in one view?

For example, let's say I have a client that can have any number of addresses in the database. Is there a way to list each column of each address, possibly a number, as part of an alias (for example, columns such as customer ID, name, Street_ address, Street_2 address, etc.)?

Thank!

+3
source share
3

- . OPENROWSET , , , -.

, , StackExchange.

, SQL, . . .

, ?

: " SQL- OPENROWSET "

, , - !

: " SQL Server, XML, HTML" ( "Covers.NET!" , 2002 !).

( ), PIVOT 2005 , PIVOTs CASE .

, ( ).

+3

- :

CREATE VIEW customer_addresses AS
    SELECT t.customer_id,
           t.customer_name,
           a1.street AS address_street_1,
           a2.street AS address_street_2
      FROM CUSTOMER t
 LEFT JOIN ADDRESS a1 ON a1.customer_id = t.customer_id
 LEFT JOIN ADDRESS a2 ON a2.customer_id = t.customer_id

, . , ( ).

+3

, . , , .

, , , , 4 , " " . , , /, .

+3

Source: https://habr.com/ru/post/1750329/


All Articles