update two or more tables with the single statement - sql

How do i update two or more two tables without the help of where clause.
Thanks...

You can do this by using an updateable view and instead of trigger.
For this you need to create a view on your base tables and add an "instead of" trigger to this view
Later you can update the view directly.
For more information check the following links
how to update multiple tables in oracle DB?
Update multiple table column values using single query

In SQL Server you cannot update two tables in one update statement even in an updateable view.

Related

Cannot add records to Access linked table via query, but can update and delete via query and add directly to the table

I have an Access front end for a SQL database. I can add, update and delete records directly in the tables from Access. I can also update and delete rows from queries based on those tables. However, I am unable to add records to any queries. They can be simple queries based on one table with no criteria, it doesn't matter. I am unable to add rows.
I am the db owner, by the way, so permissions should not be a problem. Also, like I said, I can add directly to the tables, just not through queries.
Have any of you experienced this behavior?
Thank you for any help you can provide!

Drop a selection of tables

I'm aware of the commands for dropping a single table or all tables. But in this scenario I need to be able to drop a selection of tables in SQL CE. I know it is possible to do this logic on the application level but I was wondering if it was possible to do this in a single SQL command? I have been unable to find out an answer to this question elsewhere.
I have previously attempted:
drop table table1, table2, table3
But this did not work. Is it possible to do this in a single command?
No, it is not possible in a single statement: http://msdn.microsoft.com/en-us/library/ms173418.aspx

Multi-table Update in Oracle

Just like Multi-table insert(using INSERT ALL) is there multi-table Update facility in Oracle? In which version?
AFAIK there is no such facility in Oracle - you can't UPDATE multiple tables within one statement - you can use mutiple tables within an UPDATE statement but only one table can be updated.
What you could do is either wrap multiple UPDATE statements into one transaction and/or use an INSTEAD OF trigger which in turn contains multiple UPDATE statements...

Sql Server: Execute delete against updateable view with joins

In SQL it is possible to run inserts and updates against a view, as long as the view only selects data from one table. However, deletes don't seem to work quite so well. Can anyone help out?
Take this view for example:
CREATE VIEW v_MyUpdatableView
AS
SELECT x.* FROM MyPrimaryTable x
LEFT OUTER JOIN AnotherTable y ON y.MyPrimaryTableId = x.Id
I can run updates and inserts against this view and they happily pass through to MyPrimaryTable.
However, if I run a delete I receive the following exception:
View or function 'v_MyUpdatableView' is not updatable because the modification affects multiple base tables.
Quote:
DELETE statements remove data in one or more of the member tables through the partitioned view. The DELETE statements must adhere to this rule:
DELETE statements are not allowed if there is a self-join with the same view, or any of the member tables.
Data Modification Rules - Creating a Partitioned View
I would just create a stored procedure that would delete the data from two tables. I know it's not pretty, but it would work or do logical deletes, where you update a column to be "deleted".

can we insert into two tables with single sql statement?

Will it be possible to insert into two tables with same insert command?
No you cannot perform multiple inserts into two tables in one query.
No you can't.
If you want to ensure the atomicity of an operation that requires data to be inserted into 2 tables, you should protect it in a transaction. You either use the SQL statements BEGIN TRAN and COMMIT TRAN, or you use a transaction boundary in whatever language you're using to develop the db access layer. E.g. something like Connection.StartTransaction and Connection.Commit (or Connection.Rollback on an error).
You can call a stored procedure with inserts into two tables.
Maybe in a future release of MySQL you could create a View containing the 2 tables and insert into that.
But with MySQL 5.1.41 you'll get the error:
"Can not modify more than one base table through a join view"
But inserting into 2 tables with 1 query is a weird thing to do, and I don't recommend it.
For more on updatable views check out the MySQL reference.