<p>Is there an automatic way in SQL Server 2005 to create a database from several tables in another database? I need to work on a project and I only need a few tables to run it locally, and I don't want to make a backup of a 50 gig DB.</p>

<p><strong>UPDATE</strong></p>

<p>I tried the Tasks -> Export Data in Management studio, and while it created a new sub database with the tables I wanted, it did not copy over any table metadata, ie...no PK/FK constraints and no Identity data (Even with Preserve Identity checked).</p>

<p>I obviously need these for it to work, so I'm open to other suggestions. I'll try that database publishing tool.</p>

<p>I don't have Integration Services available, and the two SQL Servers cannot directly connect to each other, so those are out.</p>

<p><strong>Update of the Update</strong></p>

<p>The Database Publishing Tool worked, the SQL it generated was slightly buggy, so a little hand editing was needed (Tried to reference nonexistent triggers), but once I did that I was good to go.</p>

[{'answer_id': 24548, 'author': 'Fredrik Kalseth', 'author_id': 1710, 'author_profile': 'https://Stackoverflow.com/users/1710', 'pm_score': 3, 'selected': True, 'text': '<p>You can use the <a href="http://www.codeplex.com/sqlhost/wiki/view.aspx?title=database%20publishing%20wizard" rel="nofollow noreferrer">Database Publishing Wizard</a> for this. It will let you select a set of tables with or without the data and export it into a .sql script file that you can then run against your other db to recreate the tables and/or the data.</p>\n'}, {'answer_id': 24562, 'author': 'Dima Malenko', 'author_id': 2586, 'author_profile': 'https://Stackoverflow.com/users/2586', 'pm_score': 0, 'selected': False, 'text': '<p>Integration Services can help accomplish this task. This tool provids advanced data transformation capabilities so you will be able to get exact subset of data that you need from large database.</p>\n\n<p>Assuming that such data is needed for testing/debugging you may consider applying Row Sampling to reduce amount of data exported.</p>\n'}, {'answer_id': 24569, 'author': 'Louis Salin', 'author_id': 160, 'author_profile': 'https://Stackoverflow.com/users/160', 'pm_score': 1, 'selected': False, 'text': '<p>Create your new database first. Then right-click on it and go to the Tasks sub-menu in the context menu. You should have some kind of import/export functionality in there. I can\'t remember exactly since I\'m not at work right now! :)</p>\n\n<p>From there, you will get to choose your origin and destination data sources and which tables you want to transfer. When you select your tables, click on the advanced (or options) button and select the check box called "preserve primary keys". Otherwise, new primary key values will be created for you.</p>\n'}, {'answer_id': 24657, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 1, 'selected': False, 'text': "<blockquote>\n  <p>I know this method can hardly be called automatic but why don't you use a few simple SELECT INTO statements?</p>\n</blockquote>\n\n<p>Because I'd have to reconstruct the schema, constraints and indexes first. Thats the part I want to automate...Getting the data is the easy part.</p>\n\n<p>Thanks for your suggestions everyone, looks like this is easy.</p>\n"}, {'answer_id': 22855509, 'author': 'ravi', 'author_id': 3496806, 'author_profile': 'https://Stackoverflow.com/users/3496806', 'pm_score': -1, 'selected': False, 'text': '<ol>\n<li>Create new database</li>\n<li>Right click on it,</li>\n<li>Tasks -> Import Data</li>\n<li>Follow instructions</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/24541', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1965/']