How to update database table with table in SQL - sql

I have a SQL Server table with columns including Ticket id, and each row corresponding to one ticket.
Weekly, I will pull data with the same columns with rows corresponding to all tickets that have been created or changed since the last pull.
My question is, what is the correct SQL command to update my existing table so that the new tickets are added and the changed tickets are updated?
Apologies, I am new to SQL. I will be using pyodbc in python with a db in SQL Server.
Edit: Ok, for anyone still looking at this, my question becomes: how can one upsert/MERGE a large json to sql server table using pyodbc?

Related

Retrieve records from table without timestamp column in SQL Server

I am using AWS RDS SQL Server as my DB. I have a few tables without a timestamp column and need to query those tables for data inserted within the last hour or so. I can't add extra columns, create trigger or change source in any way. Change Tracking (CT) feature of SQL server seems the way to go but I wanted to know is there any other way.

Details of Row Affected in SQL Server

I am learning SQL and using SQL Server Management Studio to query the database. When I run an update command, I get a message which displays the number of rows which get updated in the table, e.g. "1 Row affected".
However, I don't get the details of tables which are getting updated. This is required in case when multiple tables are updated on updating single table.

SQL Server tracking changes in data coming from Oracle link

I have a SQL Server table that I create by selecting from an Oracle view using a database link. The Oracle database is fully wrapped and comes from an external vendor.
The table has a text field for the current month's update. It doesn't have any dates or IDs. When I run the procedure to get the data I don't have any idea if the value has been the same for the last few months or had been updated, I have no idea when it was updated. I thought of going through the query row by row and detecting if the value is there and if it isn't, insert a new row with a creation date. This will provide a monthly row with any updates, keeping the older updates linked to the correct date. Maybe. I'm no expert and couldn't think of a way. Would this break? How would you solve my problem?
I don't have DBA rights in any databases.

Best way for block SQL table records in SQL Server

I have SQL Table in SQL Server like this:
In this table there are old records (Last year).
I should use this table again.But old records to be blocked (No operation taken on them (Select,Update, Delete)).
I can't modify design table and add another field like locked or date or add new table for handle operations.
Is this possible in SQL Server?
It would be very helpful if someone could explain best solution for this problem.
Thanks.

Updating in Tables in SQL Server 2008 [duplicate]

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.