Get a print out of INSERTs from a table in SQL Server [duplicate] - sql

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
SQL Server 2005 - Export table programatically (run a .sql file to rebuild it)
Generate INSERT statements from a SQL Server Table
I have a table in SQL Server 2005 and want to get a printout out of inserts so I can copy and paste them into my production server (I cannot directly link to production server).
I just want a print out of X number of records from a very large table.
select * from data where tableID > 10100;
The above is the condition I want to use to figure out which records to generate the inserts for.

Try one of the many third-party tools around that do this:
SQL Server 2008 R2 - generating INSERT statements for a table (I believe this also works / is also available for the 2005 version)
See this other SO question on the same topic (and the answers!)
SQL Server 2005 Script to Generate INSERT statements
Generate Insert Statements For a SQL Server Table
or just plain Google (or Bing) for it! There's tons of material out there....

Related

Fetching the data from two different servers in SQL Server [duplicate]

This question already has answers here:
Querying data by joining two tables in two database on different servers
(11 answers)
Closed 4 years ago.
How can I fetch the data from two different databases that are on different servers in SQL Server?
You will need to create a linked server to the server where you will execute the Query.
You can use sp_addlinkedserver to create one. You may reference here.
Sample would be for the same SQL Server
EXEC sp_addlinkedserver
N'SEATTLESales',
N'SQL Server';
GO
Once you have created the linked server. You can now reference it in your query by doing something like this:
SELECT * FROM [NameOfLinkedServer].[DatabaseInLinkedServer].[dbo].[TableInLinkedServer]
Or you can check Dave Brown's comment to your question: Here.
You can indeed do this, but I recommend against it. You can create a linked server on DB-SERVER-1, connecting it to DB-SERVER-2.
(A linked server definition is setup by the DBA. It contains the login credentials to the remote server. If you want to provide the login credentials yourself each time, that would be an openquery or openrowset command.)
You then could write a query using four part naming convention as follows, assuming you are running this query on DB-SERVER-1:
select *
from DB1.dbo.YourTable a
join [DB-SERVER-2].DB2.dbo.OtherTable b on b.ID = a.ID
Cross server joins are notorious for having performance problems. I would only do it for administrative purposes, and definitely not against large result sets.

How to create table in SQL Server 2012 using script file generated from SQL Server 2005?

How to use a script file generated from SQL Server 2005 and create the same table in SQL Server 2012?
Plus I have a script file for each table, how could I combine them all to generate my database?
Just create a database on SQL Server 2012 and run each create object script.
If some error or warning arises you can work it by demand.
note the tables got dependencies, so it's a good idea to create that tables in the right order.
You also can create the tables and put a no check in the FKs creation snipets and switch all FKs to check once all tables ar in place.
Also it's good to create all tables before creating the views, etc.

How to merge tables from 2 databases in SQL Server 2008

I'm using SQL Server 2008 - just a standard edition. Sorry if this is a rather basic question, but I know very little about SQL
I have 2 databases I've previously created using Visual Studio that would now benefit from being merged. By merged I mean copying the tables from the 2nd database to the first and deleting the 2nd database.
Is there a simple way of doing this through the SQL Management Studio?
You can use OPENROWSET to read data from one database and merge it into another.
For example:
USE DBToMergeInto;
INSERT INTO TableToMergeInto
SELECT * FROM OPENROWSET
('SQLOLEDB',
'Trusted_Connection=yes;Server=192.168.1.1\ServerToMergeFrom',
'DbToMergeFrom.dbo.TableToMergeFrom')

View the query by which a table was created in SQL Server 2000 [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to see query history in SQL Server Management Studio
I have created a table by create command in sql server, I executed the query from query analyzer and then I closed the query analyzer. Now I want to see that query by which I created the table how can I do it?
Right-click on the Table in your Object Explorer and select Script Table as... -> CREATE to -> New Query Editor Window.
In general - NO. But you can get just similar script by various scripting modules, including supplied with Sql Server 2000 (Enterprise Manager and Query Analyzer Script Table as context menu)
OR
exec sp_help 'tablename'
May provide you sufficient information for your needs

Bulk INSERT into SQL Server CE

I am using WebMatrix for a site right now, and its built-in SQL Server Compact database, and it's alright, but it only lets you create one row at a time. It has no bulk insert features (as I expected). But, see I have tens of thousands of rows in a spreadsheet.
I used to use Navicat for SQL Server which let me define a table name, then it would automatically IMPORT the spreadsheet into a table! Tens of thousands of rows, All within about 30seconds. How can I get Navicat for SQL Server to connect to WebMatrix's database for my website so I can do mass-bulk-inserts?
I have a Bulk Insert library, that you may be able to use: http://sqlcebulkcopy.codeplex.com