views:

124

answers:

4

I have to create a view from more than one table in MS Sql Server database, but i am not able to get the correct syntax for the same. need help.

thanks.

+1  A: 

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

...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.

Reference:

OMG Ponies
+1  A: 

You do this with JOINs, just like you would with a regular query.

If you can write a query that gets you the data, you should be able to write view nearly the exact same way.

Post what you have.

Joe
+1  A: 

example

create view ViewCustomerOrders
as
select * from Customer c
join Order o on o.CustomerID = c.CustomerID 
SQLMenace
A: 

Show us what you have already...

pcent