473,624 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting data from one MSSQL DB to a different MSSQL DB

5 New Member
I'm new to MSSQL (Have used MySQL for a little while) and am completely stuck. I have searched the net for days now and am amazed at how little info is out there for MSSQL.

I am selecting multiple rows from one DB and need to insert those rows in to a table in a different DB and I can not figure out how to do it. Im using PHP. I have not been able to find a function for MSSQL similar to mysql_insert_ar ray.

The SELECT output is creating a PHP form with a bunch of rows but I don't know exactly where to start with getting that data in to a table in a different database. In the past, whenever I had to do this it was using tables in the same DB but since this is seperate DB's, I am a bit lost.

Any input would be much appreciated!
Apr 3 '08 #1
7 2336
ck9663
2,878 Recognized Expert Specialist
I'm new to MSSQL (Have used MySQL for a little while) and am completely stuck. I have searched the net for days now and am amazed at how little info is out there for MSSQL.

I am selecting multiple rows from one DB and need to insert those rows in to a table in a different DB and I can not figure out how to do it. Im using PHP. I have not been able to find a function for MSSQL similar to mysql_insert_ar ray.

The SELECT output is creating a PHP form with a bunch of rows but I don't know exactly where to start with getting that data in to a table in a different database. In the past, whenever I had to do this it was using tables in the same DB but since this is seperate DB's, I am a bit lost.

Any input would be much appreciated!

Type this in google: sql server INSERT INTO


The syntax you are looking for is:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO DB2.TABLE2
  2. select * from db1..table1 where condition
  3.  

-- CK
Apr 3 '08 #2
omeek
5 New Member
Thanks for the info. How do you specify username, password etc.. for multiple databases that have different credentials? I am only familiar with doing a single mssql_connect string to one DB.

I searched Google and, so far, only found how to do a insert/select within the same database. I'll keep searching..and thanks again for your response!
Apr 3 '08 #3
ck9663
2,878 Recognized Expert Specialist
Why do you need to use different credentials to connect to other DB, if I may ask? Credentials are usually controlled on the server level and rights are filtered down to the db.

There might be some other solutions that we can suggest.

-- CK
Apr 3 '08 #4
omeek
5 New Member
Well, the way it is set up, I pull data from a database (db1) my work uses for thier ticketing software then I have that data inserted in to a table in a different database (db2) on the same server. A seperate database is used because if we were to use a table in the database I am puilling from (db1) it would void our support contract. I am doing this for a "shift hand-off" process where we need to import a list of tickets that are assigned to my team.

As for the credentials, since I am using PHP for the SQL interaction, I am under the impression that the seperate credentials are necessary.

I am using PHP for this process. The number of rows being selected will be different each time. Do you think doing some sort of loop to insert the retrieved data would work better? I am only a little familiar with "for" loops in PHP so I am at a bit of a disadvantage. Other than working with different kinds of loops, I have a really good understanding of PHP and mySQL. I had never used SQL Server until now and am a bit surprised at all the differences between the two.

Once again thanks! I appreciate you sharing your knowledge.
Apr 3 '08 #5
ck9663
2,878 Recognized Expert Specialist
Well, the way it is set up, I pull data from a database (db1) my work uses for thier ticketing software then I have that data inserted in to a table in a different database (db2) on the same server. A seperate database is used because if we were to use a table in the database I am puilling from (db1) it would void our support contract. I am doing this for a "shift hand-off" process where we need to import a list of tickets that are assigned to my team.

As for the credentials, since I am using PHP for the SQL interaction, I am under the impression that the seperate credentials are necessary.

I am using PHP for this process. The number of rows being selected will be different each time. Do you think doing some sort of loop to insert the retrieved data would work better? I am only a little familiar with "for" loops in PHP so I am at a bit of a disadvantage. Other than working with different kinds of loops, I have a really good understanding of PHP and mySQL. I had never used SQL Server until now and am a bit surprised at all the differences between the two.

Once again thanks! I appreciate you sharing your knowledge.


Two options you can do:

1. Create a stored proc in db2 to read table from db1 and insert it to the table in db2. You have to allow your stored proc to accept parameters to use for filters and such...On your PHP, call that stored proc with all the parameters. The cons: you're going to use the same credentials to connect to two db's. But it will be transparent and you're not really editing the data from db1 you're just reading it and storing it in db2 for your own process which are in the same server anyway. The pros: it's fast.

2. Am not much of a PHP programmer so you to forgive me. In your PHP, connect to db1. Using a datasource or recordset object/variable get the data you need from the table in db1. Use a loop to go through this recordset and add each row to the table in db2. Pros: you can use different credentials depending on the connection type you use. Cons: slow.

-- CK
Apr 3 '08 #6
omeek
5 New Member
Thanks for the suggestions! I think I'll start with #2 and if that fails, go with option 1.

Thanks!
-Oliver
Apr 6 '08 #7
omeek
5 New Member
CK:

I was able to use a form to submit the data (results of DB1 query) as an array in PHP then parse through the rows one by one inserting them in to the second DB!

Thanks so much for your help and suggestions!
Apr 6 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3424
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I could use inside this console application to make sure the MS SQL database is operational before I perform the insert?
4
25334
by: epaetz | last post by:
I'm doing a bcp out of a table to a file. Some of the fields in a record may have an empty string. When I bcp out to the file and examine it, the fields that have an empty string in the database now show up in the file as having one blank character. Why is bcp doing this? I don't want the blank character in my output. Thanks,
4
1625
by: Ria Van Heerden | last post by:
How do I insert data from one form into two tables in a database? I am working with ASP pages and a MSSQL database Please let me know if one of you have done this before and how this is possible Kind Regards Ria
0
1112
by: sherif | last post by:
Hi, I'm making an application using C# and i connect through it to a database made by MSSQL server but i have a problem when inserting or updating in the database in arabic that each arabic letter is replaced by a question mark (?) the code i'm using to insert is oleDbDataAdapter1.InsertCommand.CommandText=" sql Statement"; and to update is: oleDbDataAdapter1.UpdateCommand.CommandText="sql
3
1184
by: darrel | last post by:
I'm using parameterized sql for my Db updates and typically use something like this: objCommand.Parameters.Add("@pageID", System.Data.OleDb.OleDbType.numeric).Value = 24 However, I now need to add a string to a 'text' field in MsSQL. There isn't a System.data.oledbtype.text option. Is System.Data.OleDb.OleDbType.LongVarChar proper? Another option? BSTR?
2
2548
by: Igal | last post by:
I'm trying to insert a date value into MSSQL, the type of the sql filed is: "smalldatetime" and i'm trying to insert a text Variable that looks like this: "19/02/2006". .... SET update_date='" & Update_Date & "' ... i get the message: The conversion of char data type to smalldatetime data type resulted in
3
1477
by: Robert Johnson | last post by:
Hi all. Created a simple table in my db. 3 colums one is a Int set for autoincrement. Itentity True, seed 1, Incremement 1, null False. The other colums are simple VarChar(50) null false on the first and true on the last. Nothihng complicated here. create a simple test app in VS2005 and connect to MSSQL2005 server, no problem there. I can see it in Designer and preview the 3 rows of test data I added. Now, I create a form1 and DRAG...
12
2652
by: Todd Michels | last post by:
Hi all, I am trying to send data from a form and insert it into a MSSQL DB. When I submit the data I get: Warning: mssql_query() : message: The name "Todd" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. (severity 15) in "Myfile"
3
6420
by: krzys | last post by:
I have 2 databases (with different user names and different passwords), and I need to join column_1 from table_A (on first database: database_I) on column_2 from table_B (on second database: database_II). How query should likes? I want to do this in php - where should I specify different user names and diffrent passwords for databases? <?php $dbhost="server_name\instance_name,port_number";
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.