【发布时间】:2011-11-27 07:23:29
【问题描述】:
是否可以永久连接两个表?我将在哪里执行一次该查询,然后即使我退出 DBMS,它也可以自动加入?
【问题讨论】:
是否可以永久连接两个表?我将在哪里执行一次该查询,然后即使我退出 DBMS,它也可以自动加入?
【问题讨论】:
您可能想考虑创建一个view。
视图本质上是一个存储的 SQL 语句,您可以像查询表一样查询它。
create view MyView as
select TableA.Field1, TableB.Field2
from TableA
join TableB on TableB.ID = TableA.ID
select *
from MyView
【讨论】:
Primary Key,您可能需要创建 indexes 来备份视图中的加入
如果您总是同时写入并从连接中读取,则可以将它们合并为一个,然后仅从该连接中写入和选择。
--==[ before ]==--
insert into user (id, name) values (1, "Andreas");
insert into email (id, email) values (1, "andreas - at - wederbrand.se");
select user.id, user.name, user.email from user, email where user.id = email.id;
--==[ do the merge ]==--
create table user_with_email select user.id, user.name, user.email from user, email where user.id = email.id;
drop table user;
drop table email;
--==[ after ]==--
insert into user_with_email id, name, email values (2, "Bruce", "Bruce - at - springsteen.com");
select id, name, email from user_with_email;
【讨论】: