Is there an easy way to script the tables from within a database to
include the indexes etc...
Basically, if I want to script a number of tables, I can right hand
click on them and generate the script that way. What I'd like to do is
this same process in T-SQL if possible so I can build an SP which I can
then run.
It's really just a discussion point. Say we have a number of very
similar databases whereby there is a database per client and the
structure is almost the same. This was done for simplicity (rightly or
wrongly) and there is a fair amount of data.
When we take on a new client, we would need to take a copy of the
structure and create a new database with the tables from a known
'base'.
We would likely need a table to hold the names of the tables to include
from each database. We would then create an SP passing the name of the
database to copy from and one to copy to. This would then create a
script we can then automatically run to create a new database. Could
this be done in an SP where you pass these parameters, it creates
another SP with the script and then runs it ?
I've simplified some of this, so I hope it makes sense. It's not
something I would have normally done, but I'm curious how this problem
would be approached. Often people would take a script (or use a saved
one) and run that after manually creating the database.
Thanks in advance
Ryan 3 1179
In enterprise manager, right click on the database - tasks - generate
sql scripts - follow the wizard.
Ryan wrote: Is there an easy way to script the tables from within a database to include the indexes etc...
Basically, if I want to script a number of tables, I can right hand click on them and generate the script that way. What I'd like to do is this same process in T-SQL if possible so I can build an SP which I can then run.
It's really just a discussion point. Say we have a number of very similar databases whereby there is a database per client and the structure is almost the same. This was done for simplicity (rightly or wrongly) and there is a fair amount of data.
When we take on a new client, we would need to take a copy of the structure and create a new database with the tables from a known 'base'.
We would likely need a table to hold the names of the tables to include from each database. We would then create an SP passing the name of the database to copy from and one to copy to. This would then create a script we can then automatically run to create a new database. Could this be done in an SP where you pass these parameters, it creates another SP with the script and then runs it ?
I've simplified some of this, so I hope it makes sense. It's not something I would have normally done, but I'm curious how this problem would be approached. Often people would take a script (or use a saved one) and run that after manually creating the database.
Thanks in advance
Ryan
Ryan (ry********@hotmail.com) writes: Is there an easy way to script the tables from within a database to include the indexes etc...
Basically, if I want to script a number of tables, I can right hand click on them and generate the script that way. What I'd like to do is this same process in T-SQL if possible so I can build an SP which I can then run.
If you are on SQL 2000, you would have to use sp_OAmethod and friends
to run SQL-DMO. Generally, you will probably find it easier to write
it some client language which is better fitted for COM programming.
If you are SQL 2005, you would instead use SMO for scripting. I guess
you should be able to this from a CLR stored procedure. Again, T-SQL
is not the best choice here.
When we take on a new client, we would need to take a copy of the structure and create a new database with the tables from a known 'base'.
The way we do it is that we point our build tool to our version-control
system and say "get this version". Then we know exactly what we have
shipped.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx
Erland,
Thanks for the reply. It's what I thought, but always nice to confirm
it.
Thanks
Ryan
Erland Sommarskog wrote: Ryan (ry********@hotmail.com) writes: Is there an easy way to script the tables from within a database to include the indexes etc...
Basically, if I want to script a number of tables, I can right hand click on them and generate the script that way. What I'd like to do is this same process in T-SQL if possible so I can build an SP which I can then run.
If you are on SQL 2000, you would have to use sp_OAmethod and friends to run SQL-DMO. Generally, you will probably find it easier to write it some client language which is better fitted for COM programming.
If you are SQL 2005, you would instead use SMO for scripting. I guess you should be able to this from a CLR stored procedure. Again, T-SQL is not the best choice here.
When we take on a new client, we would need to take a copy of the structure and create a new database with the tables from a known 'base'.
The way we do it is that we point our build tool to our version-control system and say "get this version". Then we know exactly what we have shipped.
-- Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Saverio Tedeschi |
last post by:
Ho all SQL gurus, I've searched for samples on how to automatically
scripting SQL2000 tables to export data between databases via a sql
script. (somehing like:
INSERT INTO ..(, ,
, , , )...
|
by: Shailesh Humbad |
last post by:
Has anyone ever heard of a c++ web 'scripting' engine? I think it
would be fairly easy to make one. All that is needed is an
intermediary that compiles the code on demand and caches the...
|
by: Bibby |
last post by:
Hi, I'm interested in getting started in the programming world. I've dabbled
in C, C++ and VB6. Which would be the best language to focus my attention to
regarding the following considerations:
...
|
by: Wolfgang Keller |
last post by:
Hello,
I'm looking for a spreadsheet application (MacOS X prefered, but
Windows, Linux ar available as well) with support for Python scripting
(third-party "plug-ins" are ok) and a database...
|
by: Birahim FALL |
last post by:
Hi,
I'm very fresh to PostgreSQL, coming from Oracle.
I want to developp web applications based on apache and postgresql.
Is there an equivalent of OWA server (Oracle Web Application server) for...
|
by: A.M |
last post by:
Hi,
I am having difficulty with shell scripting in Python.
I use the following command to run a DOS command and put the return value in
a Python variable:
|
by: Vlad Dogaru |
last post by:
Hello,
I would like to learn web scripting with Python (sure, everyone uses
PHP, but I don't like the syntax and Python is more general-purpose
and... well, I guess you people know the...
|
by: pk |
last post by:
I have a problem that I would like to resolve through scripting, but
I'm not sure how to go about it (or if it's even possible.)
We're trying to work around a bug (...
|
by: xman |
last post by:
Anyone who uses SQL Server is familiar with the scripting capabilities
that the Enterprise Manager or the SSMS offer. Being able to script an
object or an entire database is great, however, often...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |