Advertisement

09.05.2005 at 02:37PM PDT, ID: 21551361
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

copy table data and indexes into another table
Tags: copy, sql, data, another
hi experts.

i am using mssql 2000

i have 2 databases, named :

db1 and db1,

i need to copy some of the tables in db1 to db2 with their indexes, foreign keys, etc.

I used :

SELECT * INTO db2.dbo.test FROM db1.dbo.test
(db2.dbo.test does not exists)

it works only for structure and data

is there any way to take indexes, foreign keys, etc ?
i need a sp for this job i think...

thanks for your help...

P.S : i can't use any third-party program because i am coding a visual basic program. so i should do this with sql (i suppose).
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: ozgurorhan
Solution Provided By: arbert
Participating Experts: 2
Solution Grade: A
Views: 828
Translate:
Loading Advertisement...
09.05.2005 at 02:58PM PDT, ID: 14825579

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 03:08PM PDT, ID: 14825617

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 03:17PM PDT, ID: 14825650

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 03:19PM PDT, ID: 14825660

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 03:43PM PDT, ID: 14825752

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:01PM PDT, ID: 14825797

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:08PM PDT, ID: 14825809

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:18PM PDT, ID: 14825826

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:19PM PDT, ID: 14825829

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:20PM PDT, ID: 14825831

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:25PM PDT, ID: 14825851

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.05.2005 at 04:38PM PDT, ID: 14825895

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.06.2005 at 02:12AM PDT, ID: 14827635

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.06.2005 at 02:17AM PDT, ID: 14827665

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.06.2005 at 04:19PM PDT, ID: 14833080

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
09.05.2005 at 02:58PM PDT, ID: 14825579

Rank: Genius

You need to generate the script that creates the table, indexes, foreign keys, etc. and then use INSERT to copy the data instead of SELECT ... INTO
 
09.05.2005 at 03:08PM PDT, ID: 14825617
I was thinking of putting the data and then altering the table, but your solutions seem fine too.. but my question was "how" ?

bu thanks for the idea..
 
09.05.2005 at 03:17PM PDT, ID: 14825650

Rank: Genius

Open enterprise manager, right click on your database, choose "All Tasks", Generate SQL Scripts.

You can take the scripts and run them from VB using the connection object with Execute.

Brett
 
09.05.2005 at 03:19PM PDT, ID: 14825660

Rank: Genius

>> but my question was "how" ?<<
How what?  Generate the script or the Insert?

The easiest way to generate the script for the structure is to use Enterprise Manager, highlight all the appropriate tables, right click "All Tasks" | "Generate SQL Scripts..."

As far as doing the INSERT that is dependent on the structure of your tables, but something like this:
INSERT db2.dbo.test
Select *
FROM db1.dbo.test

Although it is best to explcitly name the columns.
 
09.05.2005 at 03:43PM PDT, ID: 14825752
I am writing a backup module for a program that has 150-200 tables, each have indexes, foreign keys. the tables are like xxx_10_13 , xxx_14_15. each table names means another firm, so  the user should choose the ones to backup, and the script would get the name of the table from dropdown and copy it to the backup database.

so the script (i suppose it would be stored procedure) should get the constants as well as data.

- create table
- insert the data
- alter the indexes and foreign keys.

 is there any sp that copies indexes, foreign keys, defaults in mssql  ? or should i do it looping through sysobjects ?
 
09.05.2005 at 04:01PM PDT, ID: 14825797

Rank: Genius

sounds like a nightmare.  With something so small, why don't you just use the existing SQL Backup?  Are you also going to allow them to restore in this fashion???
 
09.05.2005 at 04:08PM PDT, ID: 14825809
yeah, it is a nightmare.. but they don't want to take full backup. cause they would use this program both for backup and giving data to other program users. and the given data sould not be the full backup but only some tables (which is a security issue i couldn't even care to understand).

but i am in a very bad situation now, and need help from experts. that's why i post this question.
 
09.05.2005 at 04:18PM PDT, ID: 14825826

Rank: Genius

I agree.  Not something I personally would undertake. Unfortunately we cannot give you detailed instructions how to complete this, just a broad outline.
 
09.05.2005 at 04:19PM PDT, ID: 14825829

Rank: Genius

"xxx_14_15. each table names means another firm"

So I suppose it's too late to change teh design and store all firms in one table with a "firmID" and not multiple tables.

Like we said above, your best bet is to probably generate the SQL Scripts with enterprise manager.  Another option would be to use SQLDMO to do it on the fly  (sample: http://www.sqlteam.com/item.asp?ItemID=9093).

This just has a bad feel...
Accepted Solution
 
09.05.2005 at 04:20PM PDT, ID: 14825831
i need only hints about using sysobjects table to loop through table related items to generate them automaticly. like getting the indexes of a table and create the same indexes in another one through a stored procedure.. if i could do that, i believe i can write a full functional sp that does that job.
 
09.05.2005 at 04:25PM PDT, ID: 14825851

Rank: Genius

First hint--don't ever user the sysobjects tables.  use information_schema.tables, information_schema.column_names, stored procedures (sp_fkeys, sp_pkeys, etc) to get the information.  Querying the system tables is usually a bad idea.
 
09.05.2005 at 04:38PM PDT, ID: 14825895
i tried to use sysobjects  because i saw a script like :

select sysobjects.name Table_Name,
(Select rows from sysindexes
 where id = sysobjects.id
 and indid = 0) Rows
from
 sysobjects
where
 xtype = 'u'
 and objectproperty(sysobjects.id, 'TableHasIndex') <> 0

which gives the tables without indexes...

but let me look at SQLDMO a bit.
 
09.06.2005 at 02:12AM PDT, ID: 14827635
if it helps anyone, i rewrote

http://www.databasejournal.com/img/GenDependScript.vbs_

this script written and it worked well.

thanks for the sql-dmo hint
 
09.06.2005 at 02:17AM PDT, ID: 14827665
 
09.06.2005 at 04:19PM PDT, ID: 14833080

Rank: Genius

Just remember, the dependencies generated by DMO may not always be generated in the correct order...
 
 
20080236-EE-VQP-29