I need to create a view where I’ll list certain attributes. To be more specific:
Table Clientemp –
contact
Table Cliente –
name,address
I need to get into the Clientemp the name and address attribute from the table Cliente.
So far I have:
create view "Company Clients"
select client.name, cliente.address, clientemp.contact
from cliente, clientemp
insert into clientemp (select name, address from cliente)
Will this work? Any suggestion?
Basic VIEW DDL:
As you have written the SELECT the join will result in a CARTESIAN PRODUCT (CROSS JOIN)
of the tables Clientemp and Cliente. Which will yield every possible combination of records between the two tables.
Proper syntax for an INSERT statement would be
INSERT INTO {Target}
SELECT {Column list} FROM {TableA} /* Optional Join conditions */;
Depending on the Database system your VIEW definition will likely
not allow for an INSERT statement.
However, some database systems
allow you to perform INSERTS through views if the underlying view
targets a single table and is properly qualified with columns
requiring a value to be present at the time of INSERT. (In
other words all columns that do not have a DEFAULT value specified in
the table definition.)