Updating in Tables in SQL Server 2008 [duplicate] - sql

This question already exists:
I need to update two tables in SQL [closed]
Closed 8 years ago.
I need to update one table from one database to another table on another database. This will need to be run once a day. Both tables are the same structure.
One database is called pvc_rds and the other is called kiosk. The table is REC_Materials. There is a column called sid that is unique. Both these live on the same SQL Server 2008.
I am new to this so any help would be appreciated. Thanks

The simple answer is to create a scheduled job, which contains a step that queries the source server (source database) and insert into the target database. However, you must use the complete name of the object, as described here: http://technet.microsoft.com/en-us/library/ms187879(v=sql.105).aspx
The more complicated answer depends on your overall goal. Is the source database, a transaction database and the target database the reporting database? In which case, is your goal to replicate the data using transaction or merge replication?

Use (at least) a three-part identifier.
The complete name of an object is made up of four identifiers: the server name, database name, schema name, and object name. They appear in the following format:
server_name.[database_name].[schema_name].object_name
In your case, this would simply translate to (assuming the dbo schema for your tables) :
UPDATE pvc_rds.dbo.REC_Materials
FROM pvc_rds.dbo.REC_Materials
INNER JOIN kiosk.dbo.REC_Materials
ON pvc_rds.dbo.REC_Materials.sid = kiosk.dbo.REC_Materials.sid
in order to synchronise existing records present in both databases. You can expand on this to remove records that shouldn't be there anymore and add any new records. You can save that process into a job, and make it run everyday by scheduling it.

Related

How to query PostgreSQL database table from Access?

I am very new to SQL, MS Access & PostgreSQL. So this might be a very silly question but somehow I can't figure it out. I'm trying to run SQL queries in access and my data is in a PostgreSQL database table which was linked to access by my colleague earlier. When I make this simple query why do I get an error that the table doesn't exist? Is the syntax different for linked database tables? Or is the link not yet established?
You have created a Pass-Through query. This query is executed on the server, not in Access, so you need to use the original table names from the PostgreSQL database.
So it's not FROM public_tb_change but FROM tb_change.
Or maybe FROM public.tb_change, if public isn't the default schema.
I advise to rename your linked tables to the original name (remove public_), that makes things much less confusing. The schema name is automatically added by Access when linking the tables.

Is possible determine value of column using a query to another table with stored procedures?

I'm working in a project where I need to make changes in the database to create a history of managers and status of projects and use it, instead of the already existing columns of managers and status in a projects table. The problem is: there are several aplications that may or may not be using those fields in this old table and would be almost impossible find all the aplications that use those fields to make them use the new tables.
So, I had been thinking, there is any way to create a stored procedure in a db2 database that can make the values in the manager and status columns in the projects table come from a query to the new history tables?
Sorry for my bad english.

SQL Server: Create a duplicate of a database without the data

I have a database called AQOA_Core with huge amount of data.
I have a newly created database called AQOA_Core1 which is basically empty. I want to write a query to duplicate AQOA_Core to AQOA_Core1 without the data. I guess to be precise I want to create a skeleton of the primary database into the secondary database.
PS: I use Toad for my database operations.
You can use SQL Server Script Wizard for scripting database objects. You can exclude data, and select the database object types you want to include in your script
Please check the SQL Server guide I referenced above,
I hope it helps you

Does Modifying Data in Access Table Modify Data in an ODBC-connected Oracle SQL table?

I am new to access. I am using a tool/access database someone built, and it has an ODBC connection to an Oracle SQL database in it.
There are different queries on the side panel, and some of them are delete queries.
If I run these delete queries will they just modify data in my local access database without modifying the data in the Oracle Database?
Yes these will change something in the database whether its linked with another access database table or oracle table and within the database. To review the query you can open the queries in design view and run a normal select query so you can see what the queries are deleting. You can have a normal table image and or globe with a arrow in front pointing towards the table then its linked. A lot of times when I am testing I just run select queries and then I make a copy of what I will be deleting just in case anything goes wrong.

How do you transfer all tables between databases using SQL Management Studio?

When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. Is there a way to export all of the data?
If this is not possible, could you advise on how I could do the following:
I have two databases, with the same table names, but one has more data than the other
They both have different database names (Table names are identical)
They are both on different servers
I need to get all of the additional data from the larger database, into the smaller database.
Both are MS SQL databases
Being that both are MS SQL Servers, on different hosts... why bother with CSV when you can setup a Linked Server instance so you can access one instance from the other via a SQL statement?
Make sure you have a valid user on the instance you want to retrieve data from - it must have access to the table(s)
Create the Linked Server instance
Reference the name in queries using four name syntax:
INSERT INTO db1.dbo.SmallerTable
SELECT *
FROM linked_server.db.dbo.LargerTable lt
WHERE NOT EXISTS(SELECT NULL
FROM db1.dbo.SmallerTable st
WHERE st.col = lt.col)
Replace WHERE st.col = lt.col with whatever criteria you consider to be duplicate values between the two tables.
There is also a very good tool by Redgate software that syncs data between two databases.
I've also used SQL scripter before to generate a SQL file with insert statements that you can run on the other database to insert the data.
If you right-click on the database, under the Tasks menu, you can use the Generate Scripts option to produce SQL scripts for all the tables and data. See this blog post for details. If you want to sync the second database with the first, then you're better off using something like Redgate as suggested in mpenrow's answer.