sql-server


Generate a script of inserts from existing data with a select clause in SQL Server


I know that in SQL Server you can right click on a database, go to tasks, generate scripts, pick a table etc. and generate a script that inserts the data into the table as shown here
Is there any way I can restrict the data that is being scripted out by specifying some select clauses? For example, I might want to script out only the top 100 rows in a table or all records from the Employees table that has an IsManager flag set.
If I can't do it using tasks -> generate scripts functionality, is there any other alternative way or tool?
I don't know if this can be done directly in SSMS, but you could create a query to return the content of the sql file (at least the insert statements):
SELECT 'insert into yourtable (id,othercol) values (' + cast(id as varchar) + ',''' + othercol + ''');'
FROM yourtable
SQL Fiddle Demo
Be sure to cast your non-varchar fields to varchar.

Related Links

load into Fact Table
Sql query including a unicode character returns wrong result
How do I validate SQL tables data using a schema
C# SQL connection string best practice
SQL Server combine rows into single column
Sum monthly amount and output for last day of month
SSRS referring to Database Project in the solution
Error when trying to execute stored procedure
Get actual database size in SQL Server 2012 in GB?
Simple results list from SQL Server stored procedure using Codefluent
SQL Report Error - [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name
How to get distinct column in SQL Server?
Powershell returns negative exit code while script results are correct
Spark program cannot open SQL Server context?
Sql server error 916 when using a trigger that selects data in other database (outside sql server only)
Convert rows from a NoSQL schema to columns in SQL Server

Categories

HOME
sharepoint
tensorflow
cntk
cluster-computing
sidekiq
numpy
elixir
laravel-5.3
cpu-architecture
reportportal
travis-ci
matplotlib
apollo
chaiscript
recyclerview
jrebel
gspread
websphere-liberty
currency
google-classroom
image-recognition
informatica-powercenter
phoenix
scenebuilder
factor-analysis
yosys
samsung-mobile
printdocument
onesignal
metadata-extractor
winscp
protobuf-net
picturebox
pdflatex
spreedly
mongoexport
duktape
flex4.5
jrules
google-account
service-fabric-stateful
taglib
tiddlywiki
tofixed
gce
system.web.ui.webcontrols
pdflib
chessboard.js
try-finally
multifile-uploader
gherkin
scriptlet
group-concat
magento-1.4
galaxy
mysqldumpslow
matcaffe
rad
ipojo
mogrify
gray-code
isml
pylearn
virus
python-ggplot
belongs-to
cloudpebble
ogr2ogr
spdy
codeigniter-a3m
late-static-binding
internal
facebook-chat
astyanax
git-filter-branch
linkedhashset
static-variables
cross-domain-policy
webkit-transform
coff
galaxy-tab
authenticode
j-interop
grooveshark
multibyte-functions
rd

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App