Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating view across different databases

Tags:

If I have database D1 and database D2, and table T1 under database D1 and table T2 under database D2, is it possible to create a view of T1 under database D2 in MySQL. If so, can you show me the syntax.

Both the databases are on the same machine.

like image 874
Ank Avatar asked May 22 '12 01:05

Ank


People also ask

Can you create a view from another database?

Yes you can - the t-sql syntax is the same as within any other cross database call (within a stored procedure for example). Show activity on this post. Show activity on this post.

How do you create a view from one database to another in SQL Server?

SQL Server CREATE VIEW First, specify the name of the view after the CREATE VIEW keywords. The schema_name is the name of the schema to which the view belongs. Second, specify a SELECT statement ( select_statement ) that defines the view after the AS keyword. The SELECT statement can refer to one or more tables.

Can a SQL view be created from another view?

Views can be created from a single table, multiple tables or another view.


1 Answers

CREATE VIEW `D2`.`example` AS SELECT * FROM `D1`.`T1`; 
like image 191
jnrbsn Avatar answered Sep 30 '22 03:09

jnrbsn