I've a Sybase database where I will make a LOT of changes, and I would like to make my changes (currently using PowerDesigner 16), save it as .SQL then generate a .SQL to migrate my initial database to the new database structure.
I don't care about the data, I just want to update the structure with this script.
Any idea how to create this script?
EDIT: It has nothing to do with the given "duplicate", the other ticket is speaking on how to export the sql for SP/... In my case I only want the difference between the two sql
If you don't have one, you can create a model from your initial database, with File > Reverse Engineer > Database.
Create a copy of this model with File > Save As (as type Archived PDM), say copy.apm.
Then modify the model as you wish.
Then use Database > Apply Model Changes to Database, using the option Using an archive model (select the above copy.apm), to generate the ALTER script.
Anybody looking for a program agnostic way of generating the DDL for a database could use the ddlgen program that comes with ASE
See http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc30191.1572/html/utilityguide/CHDBBGGC.htm
So to create the DDL of database pubs2, you could do something like
ddlgen -Usa -Ppassword123 -SSERVERNAME -TDB -Npubs2 -Ooutput_file.sql
Related
I have developed a SQL Express database. I need to backup all but one table in that database in an automated way. I was thinking i could write a SQL script to do this, trigger it using sqlcmd from a batch file but not sure how to write that SQL script.
I was also thinking, if nothing else possible, i could create a second db that has the tables i want to backup then i write a script that copys data 'into' the second db and then do a auto backup of that entire db. This has the disadvantage of having a procrastinated unpacking of that backup when wanting to use it - its not a small install script.
Is this a possibility, is it the only option or is there tools for SQL Express to do this?
There is no option to exclude just one table while backing up .Few things i could think of
1.Right click database ->Tasks ->generate scripts ->exclude the table you want and choose to save the script and run this every time
2.you could also choose Export option,but since you are using SQL Express,you wont have the option to save this package
Keep the large table in a different database and just backup the original database. You can still use the large table even in a different database, i.e.
SELECT *
FROM MyDb.dbo.SomeTable s
JOIN OtherDb.dbo.LargeTable l
ON (expression);
I created a small database in dbDesigner which includes 4 tables, and I want to add these tables with their relationships to a database on a SQL Server. How can I do this?
Best practice for this that I am aware of, is using Management Studio's functionality for this.
The following steps will produce a file containing an SQL script you can run on any server you want in order to import the schema (with or without the data).
Right click on you database.
Select Tasks > Generate scripts
Click Next
Choose Script entire database and all database objects
Select Save to file and Single file
If you want to export data as well, click on Advanced and change Types of data to script to Schema and data (default is schema only)
Click Next ... Next.
Run the generated file on the server you want to import the schema to.
I have two database named: olddatabase and newdatabase. I want to create a new database named newdatabase2 then copy database structure from newdatabase to newdatabase2 and then convert data from olddatabase to newdatabase2.
To copy database structure from newdatabase to newdatabase2 I use Transfer SQL Server Object Task component in SSIS, and then execute SSIS Package to convert data. But in step 1 I dont now how to create new database named newdatabase2. Currently I create the database manually.
There is a "Transfer Database Task". You can use it to make a copy of newdatabase to newdatabase2:
EDIT:
or you can use the "Copy Database Wizard" once. It will generate an SSIS package and a SQL Server job, then you can re-use it as many times as you want.
EDIT2:
it would't make much sense to open on BIDS because you will only see something like this:
I don't think these packages are meant to be editable.
You can access it, though:
How do I copy data from multiple tables within one database to another database residing on a different server?
Is this possible through a BTEQ Script in Teradata?
If so, provide a sample.
If not, are there other options to do this other than using a flat-file?
This is not possible using BTEQ since you have mentioned both the databases are residing in different servers.
There are two solutions for this.
Arcmain - You need to use Arcmain Backup first, which creates files containing data from your tables. Then you need to use Arcmain restore which restores the data from the files
TPT - Teradata Parallel Transporter. This is a very advanced tool. This does not create any files like Arcmain. It directly moves the data between two teradata servers.(Wikipedia)
If I am understanding your question, you want to move a set of tables from one DB to another.
You can use the following syntax in a BTEQ Script to copy the tables and data:
CREATE TABLE <NewDB>.<NewTable> AS <OldDB>.<OldTable> WITH DATA AND STATS;
Or just the table structures:
CREATE TABLE <NewDB>.<NewTable> AS <OldDB>.<OldTable> WITH NO DATA AND NO STATS;
If you get real savvy you can create a BTEQ script that dynamically builds the above statement in a SELECT statement, exports the results, then in turn runs the newly exported file all within a single BTEQ script.
There are a bunch of other options that you can do with CREATE TABLE <...> AS <...>;. You would be best served reviewing the Teradata Manuals for more details.
There are a few more options which will allow you to copy from one table to another.
Possibly the simplest way would be to write a smallish program which uses one of their communication layers (ODBC, .NET Data Provider, JDBC, cli, etc.) and use that to take a select statement and an insert statement. This would require some work, but it would have less overhead than trying to learn how to write TPT scripts. You would not need any 'DBA' permissions to write your own.
Teradata also sells other applications which hides the complexity of some of the tools. Teradata Data Mover handles provides an abstraction layer between tools like arcmain and tpt. Access to this tool is most likely restricted to DBA types.
If you want to move data from one server to another server then
We can do this with the flat file.
First we have fetch data from source table to flat file through any utility such as bteq or fastexport.
then we can load this data into target table with the help of mload,fastload or bteq scripts.
In "Back UP" I only get a bak file, but I would like to create .sql file
Use SQL Server's Generate Scripts commend
right click on the database; Tasks -> Generate Scripts
select your tables, click Next
click the Advanced button
find Types of data to script - choose Schema and Data.
you can then choose to save to file, or put in new query window.
results in CREATE and INSERT statements for all table data selected in bullet 2.
This is a possible duplicate of: SQL script to get table content as "SELECT * FROM tblname"
To do a full database backup to File/Query you can use the 'Generate Scripts...' option on the Database.
Open SQL Server Management studio, right click on the database and choose 'Tasks->Generate Scripts...'
Then use the wizard to backup the database. You can script the whole database or parts of it. Two important options: In the 'Advanced' section, you will probably want to ensure 'Type of backup = 'Schema and Data' and the 'Script Statistics' is on.
This will produce a *.sql file that you can use as a backup that includes the schema and table data.
Ok, I read through most of these, but I had no "advanced button". But, there is still a way to do it, it's just a little hard to find, so here you go:
You can generate a script from a database, see http://msdn.microsoft.com/en-us/library/ms178078.aspx
If you want to create a script of your database you right-click on the databases and Generate Scripts (it's in different sub-menus depending on what version of SQL and Enterprise Manager / SQL Server Management studio you're using).
That will, however, only get you the database objects. It will not generate scripts for data. Backing up a database will give you all of the database objects as well as the data, depending on what recovery model your database is set to.
This fellow may have achieved what you are trying to do by creating the backup, and then restoring it and giving it a new name.
This approach copies the data along with all of the database objects.
If you want a file with insert statements for your data have a look here:
This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It's very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes.
http://vyaskn.tripod.com/code.htm#inserts