I have two tables, 2012 and 2018, each in different databases. I am currently using SQL Server. The 2012 table has data filled in, while the 2018 table has the same exact columns, but is empty. I want to copy data from the 2012 table to the 2018 table. I tried looking it up online, but most of the information pertained to other versions of SQL (MySQL, Oracle, etc.) I would very much appreciate some help with this. Thank you.
123392
I have a database called foo and a database called bar. I have a table in foo called tblFoobar that I want to move (data and all) to database bar from database foo. What is the SQL statement to do this?
68411
What is the best procedure for merging work done on a development copy of a site to the live production copy? Often times there has been a lot of new content added to the site since development started on the newest features. And most additions to a site will involve database changes. So copying any new files is easy, but what about the database? How do you merge your changes with the existing production database without losing new content that was added since the last time you updated the production site? Are there any modules that help with this?
95317
We have a setup where the production SQL Server databases are replicated to an offsite location using SQL Server Replication (transactional replication).  I am looking at using  to get the updated data in order to perform some processing and add values to a cache. Before I start down this road, does anyone know if it's possible to use Change Tracking on a replication target? It seems like it should work, but it also seems complex enough that there would be gotchas.
108409
When I write a query like this...  select * from table1 t1 join table2 t2 on t1.id = t2.id   Does the SQL optimizer, not sure if that is the correct term, translate that to...  select * from table1 t1, table2 t2 where t1.id = t2.id   Essentially, is the Join statement in SQL Server just an easier way to write sql? Or is it actually used at run-time?  Edit: I almost always, and will almost always, use the Join syntax. I am just curious what happens.
32195
I have SQL Server 2012 backup files and want to restore these to SQL Server 2016/2014. Will it work?  I need to find this out before I uninstall SQL Server 2012.
60682
I have the following QUERY  =query(XX!A2:A;" select A where A&gt;'50' ")   and  =query(YY!A2:A;" select A where A&gt;'50' ")   how do I combine these two data sources so I don't have to have two separate columns they process data to?   best would be if the 1st row from XX is followed by the 1st row of YY, 2nd row followed by 2nd row... and so on If the above option is not easily possible, it is OK for one query to be followed by the second one (if I expect correctly that the start of the second will be moved with newly added data into the first one)
33576
Maybe I'm searching for the wrong thing, but I can't see how I can do this.  I have two servers:   Server A (has SQL Server 2012 installed) Server B (has SQL Server 2014 installed)   Server A provides an API via IIS. The code both inserts and gets data from the database depending on the API call.  Server B does exactly the same for its local database.  I would like to have it so that the two databases are consistent copies of each other. I do believe this is what HA accomplishes.   So a load balancer, for example, might direct API calls to A sometimes, and B sometimes, but the data needs to be consistent either way.  I found some documentation on HA for SQL Server 2012, but not on how to do this for a mixed environment of 2012 and 2014.  Any help or pointers to documentation would be great! Thanks.
18391
I'm trying to write a query that extracts and transforms data from a table and then insert those data into another table. Yes, this is a data warehousing query and I'm doing it in MS Access. So basically I want some query like this:  INSERT INTO Table2(LongIntColumn2, CurrencyColumn2) VALUES   (SELECT LongIntColumn1, Avg(CurrencyColumn) as CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1);   I tried but get a syntax error message.  What would you do if you want to do this?
15128
I'm currently developing an application using a MySQL database.  The database-structure is still in flux and changes while development progresses (I change my local copy, leaving the one on the test-server alone).  Is there a way to compare the two instances of the database to see if there were any changes?  While currently simply discarding the previous test server database is fine, as testing starts entering test data it could get a bit tricky. The same though more so will happen again later in production...  Is there an easy way to incrementally make changes to the production database, preferably by automatically creating a script to modify it?     Tools mentioned in the answers:    (Commercial)     (Commercial)   (Commercial)
14862
I am trying to query two tables and get results like the following:  Section    Names shoes      AccountName1, AccountName2, AccountName3 books      AccountName1   The tables are:  CREATE TABLE dbo.TableA(ID INT, Section varchar(64), AccountId varchar(64));  INSERT dbo.TableA(ID, Section, AccountId) VALUES (1 ,'shoes','A1'), (2 ,'shoes','A2'), (3 ,'shoes','A3'), (4 ,'books','A1');  CREATE TABLE dbo.TableB(AccountId varchar(20), Name varchar(64));  INSERT dbo.TableB(AccountId, Name) VALUES ('A1','AccountName1'), ('A2','AccountName2'), ('A3','AccountNAme3');   I saw a few questions answered saying to use "XML PATH" and "STUFF" to query the data to get the results I am looking for, but I think there is something missing.  I have tried the below query and get the error message:     Column 'a.AccountId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.   I don't have it in the SELECT clause of either query, but I assume the error is because AccountId is not unique in TableA.  Here is the query I am currently trying to get working correctly.  SELECT section, names= STUFF((     SELECT ', ' + Name FROM TableB as b  WHERE AccountId = b.AccountId FOR XML PATH('')), 1, 1, '') FROM TableA AS a GROUP BY a.section
29248
Background  I would like to provide the subset of my database required to reproduce a select query. My goal is to make my computational workflow reproducible (as in ).  Question  Is there a way that I can incorporate this select statement into a script that dumps the queried data into a new database, such that the database could be installed on a new mysql server, and the statement would work with the new database. The new database should not contain records in addition to those that have been used in the query.  Update: For clarification, I am not interested in a csv dump of query results. What I need to be able to do is to dump the database subset so that it can be installed on another machine, and then the query itself can be reproducible (and modifiable with respect to the same dataset).   Example  For example, my analysis might query a subset of data that requires records from multiple (in this example 3) tables:  select table1.id, table1.level, table2.name, table2.level         from table1 join table2 on table1.id = table2.table1_id         join table3 on table3.id = table2.table3_id        where table3.name in ('fee', 'fi', 'fo', 'fum');
96831
I'm using SQL Server (2008 R2 in this case) and I am backing up my databases into backup devices (one per database). Every Sunday the device is overwritten with a new full backup, every night a differential backup is added and every hour a transaction log backup is added to the backup device.  When restoring this onto a new server using SSMS I first create a new database, then add the backup device and then restore from that backup device. I then have to manually select the applicable files:   The Full backup (always the first one in the list) The latest differential backup All transaction log backups that came after the last differential backup.     This works fine for the occassional restore, but I need to automate this in T-SQL.   There is some logic on which files to pick, but I don't even know how to get to the content of the backup device yet.  I would like to have a stored procedure that takes the name of the database and the backup device and restores the latest version. Anybody knows of such a thing?  Or do I miss something here and there is a simple command for this?
4924
I have a database with account numbers and card numbers. I match these to a file to update any card numbers to the account number, so that I am only working with account numbers.   I created a view linking the table to the account/card database to return the Table ID and the related account number, and now I need to update those records where the ID matches with the Account Number.  This is the Sales_Import table, where the account number field needs to be updated:  LeadID  AccountNumber 147         5807811235 150         5807811326 185         7006100100007267039   And this is the RetrieveAccountNumber table, where I need to update from:  LeadID  AccountNumber 147         7006100100007266957 150         7006100100007267039   I tried the below, but no luck so far:  UPDATE [Sales_Lead].[dbo].[Sales_Import]  SET    [AccountNumber] = (SELECT RetrieveAccountNumber.AccountNumber                            FROM   RetrieveAccountNumber                            WHERE  [Sales_Lead].[dbo].[Sales_Import]. LeadID =                                                  RetrieveAccountNumber.LeadID)    It updates the card numbers to account numbers, but the account numbers gets replaced by NULL
87815
I've been given a Sybase .db file by a client and I need to import that into a new SQL Server database so that I may see the data as well as the tables and their relationships, any ideas on how that might be done shall be really appreciated :)
29641
on SQL Server 2005, we do a weekly full backup with nightly incremental backups.   I want to know if it is possible to restore a single table from a backup, either to the source database or a different one.   I can not find any clear answer online.   Thanks in advance.
47739
SQL Server - What is the best method to run the same query over multiple databases on multiple instances? for example we have many application databases, with the same schema that need to have information aggregated.  I currently use a script that relies on linked servers already being setup and a table that identifies which instance and database to loop through.          /* declare some cursor variables and the dynamic sql string variable */     DECLARE @currentDB          nvarchar(64)     DECLARE @connectionstring   nvarchar(256)     DECLARE @sqlstring          nvarchar(max)  CREATE TABLE #TEMP1                 (                      currentDB      varchar(32)                     ,field1         varchar(128)                     ,field2         smallint                     ,field3         datetime                 )  /* Build and open the cursor */ DECLARE connectioncursor CURSOR FAST_FORWARD FOR     SELECT  currentDB, connectionstring     FROM    [admin].dbo.DatabaseList     WHERE   dbtype = 'PROD' OPEN    connectioncursor FETCH NEXT FROM connectioncursor INTO @currentDB, @connectionstring  /* Start the loop through db list */ WHILE @@FETCH_STATUS = 0     BEGIN         /* Build and set the sql string */         SET @sqlstring =             '                 select                          ''' + @currentDB + '''                         ,field1, field2, field3                         from ' + @connectionstring + '.dbo.table1             '          /* Insert the results from the iteration and fetch the next db */         INSERT INTO #TEMP1 exec sp_executesql @sqlstring         FETCH NEXT FROM connectioncursor INTO @currentDB, @connectionstring     END  /* Kill the cursor */ CLOSE connectioncursor DEALLOCATE connectioncursor   select * from #TEMP1  -- some output   Be gentle I'm a TSQL newbie!
103953
I'm afraid that I already know the answer to my question, but I'll ask it anyway:  When there are two MySQL DB servers, can I access data that is stored on the other server?   In other words: Can I somehow do this:  INSERT INTO table (x, y, z)    SELECT x, y, x+y       FROM [otherserver].[database].[table]   Is the answer really as short as "No"?