Update table with random data - sql

This is an MS Access 2010 related question.
Is it possible to update the (empty) field of an existing table with data that have no connection with those already in the other fields of the table?
Assuming I have a field called "Letters" with 3 records (A, B and C). How can I update the field "Numbers" with 1, 2 and 3?
There is no connection at all between the values. I just want them to be in the same table. This should be done for large records and multiple fields.
Basically I am have to hold some reference date in the database and I would prefer to have them all in a single table.
The below retrieves the right numbers of records but they are all empty...
UPDATE tblDestination SET tblDestination.Numbers = [tblSource].[Numb];

Related

Replicating a VLOOKUP (with column insertion) in MS SQL?

I am trying to replicate a VLOOKUP I have done in Excel in SSMS. I have two tables - table 1 is an application master listing, table 2 is an application listing. I want to simply verify that every column in table 1 has an identical match in table two. I also want to have my results populate with an inserted column, column B with the results.
I have already done a very straight forward VLOOKUP in Excel with a 1:1 match. I now have Col A with the application master listing names, and then the new lookup column B with the 1:1 match.
Does anyone know how to go about this in SQL?

Read value from a Table to another Table per automatic?

Its possible to read a value from one field to another field in SQL Server per automatic?
Like you can write GETDATE() at field "Default value and bindings" in SQL Server to get current date per automatic when you do a insert.
I want that a value copies from table A, row 1 to table B newly inserted row?

Migrate data between two SQL databases with identity column

Here is the scenario... I've two databases (A & B) with same schema but different records. I'd like to transfer B's data into corresponding tables in DB A.
Lets say we have tables named Question and Answer in both databases. DB A contains 10 records in Question table and 30 in Answer table. Both tables have identity column Id starting with 1(& auto increment), and there is 1 to many relation between Question and Answer.
In DB B, we have 5 entries in Question table and 20 in Answer.
My requirement is to copy data of both tables from source DB B into destination DB A without having any conflict in identity column while maintaining the relation between two tables during data transfer.
Any solution or potential workaround would be highly appreciated.
I will not write SQL here but here is what I think can be done. Make sure to use Identity insert ON and OFF.
Take maxids of both tables from DB A like A_maxidquestion and A_maxidanswer.
Select from B_question . In select column add derived col QuestionID+A_maxidquestion.This will be your new ID.
Select from B_Answer . In select column add derived col AnswerID+A_maxidanswer and fk id as QuestionID+A_maxidquestion.
Note- Make sure Destination table is not beeing used by any other process for inserting values while you are inserting
One of the best approaches to something like this is to use the OUTPUT clause. https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-2017 You can insert the new parent and capture the newly inserted identity value which you can use to insert the children.
You can do this set based if you also include a temp table which would hold the original identity value and the new identity value.
With no details of the tables that is the best I can do.

Comparison of two tables based on a cross reference of columns in SQL Server

My question is about comparison of fields based on the mapping table SQL Server. In the attached image, I wanted to compare values of Table 1 and Table 2 based on the mapping provided in Table 3. For example, we need to check values of Table 1's Field 1 with Table 2's Field_3_New and other columns likewise. Mapping of these columns to compare is placed in Table 3.
I want to check, whether Table 1's Field 1 values are matching with Table 2's Field 3_NEW's values or not. We came to know that Table 1's Field 1 values have a match with Table 2's Field 3_New values based on the field mapping provided in Table 3. The above is an example scenario, I'm dealing with 40 odd fields like this.

How to replicate records using PLSQL in two tables

I have two existing tables and many records already added.
formula(formulaId,formulaName,formulaType)
and formula_detail(detailId,formulaId,fieldType,value)
Now there is change in formula table and new column is being added , branchId as
formula(formulaId,formulaName,formulaType,branchId),
and branch table is branch(branchId,branchName)
I want to copy and paste every existing record in formula table for every branch.
e.g if there are 3 existing records in formula table (with ID 1,2,3) and 2 branches. Then copy paste operation should produce total new (3*2)=6 records in formula table and also replicate records in formula_detail table for every newly created formula as follows
for formulaId 1 , If there were 5 records in formula_detail table, then copy paste in formual_detail table will have (2*5) new records added in formual_detail table.
I tried some solutions but number of are records huge and script is taking time. Please help. If need any test code I can add.
First of all replicating same column in detail table is against the Normalized Form used in your Data model.
Still If you want to add the column anyway,
Add the column using ALTER statement in formula_detail table
Try using this Merge statement
.
MERGE INTO formula_detail fd
USING (SELECT formulaId, branchId from Formula) temp
ON (fd.formulaId=temp.formulaId)
WHEN MATCHED THEN
UPDATE SET fd.branchId=temp.branchId;