?
Solved

SQL Server Export Sample of 100 Records

Posted on 2012-08-19
3
Medium Priority
?
581 Views
Last Modified: 2012-08-20
I would like the step-by-step instructions on how to export (extract) about 100 Records from an existing SQL Server Database (Microsoft SQL Server 2008R2 64-Bit) that contains thousands of records. One of our software developers has requested that we extract a sample of the existing SQL Server Databse and forward (ftp) it to them for testing.

I have limited exposure/experience with SQL Server and have attempted to locate this process using SQL books without any success.

Thanks,
ECSI06
0
Comment
Question by:ECSI06
3 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 498 total points
ID: 38310420
>about 100 Records from an existing SQL Server Database
Assuming you mean 100 records from a table

-- This will return some number around (above?) 100 random rows from any table
SELECT column1, column2, column3
FROM YourTable
TABLESAMPLE (100 rows)

http://technet.microsoft.com/en-us/library/ms189108(v=sql.105)
0
 
LVL 9

Accepted Solution

by:
Vijaya Reddy Pinnapa Reddy earned 501 total points
ID: 38310697
Assuming the database name is AdventureWorks2008R2

1.Right-click the AdventureWorks2008R2 in SQL Management Studio
2.Go to Tasks and then Export data, you'll then see an easy to use wizard.
3.Your database will be the source, you can enter your SQL query

Example:
USE AdventureWorks2008R2 ;
GO
SELECT FirstName, LastName
FROM Person.Person
TABLESAMPLE (100 ROWS) ;

4.Choose Excel(or anyone from the list) as the target
5.Run it at end of wizard
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 501 total points
ID: 38311393
You can also use this approach (fix the obvious typo in xSELECT)
xSELECT TOP(100) Col1, Col2, Col3, ...
FROM YourTableName
ORDER BY NEWID()
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question