I'm looking for a command line tool to generate DDL for both tables and indexes (nothing more complicated is needed) for some Sybase tables in databases that I take care of. I have access to GUI tools for viewing the individual DDLs, and I could cut and paste them, but I would like something that will go through all the tables in a database and generate some nice text files that I can get checked into CVS.
I tried using a tool called ddlgen, which was provided by Sybase, but it just threw exceptions like this:
bash-3.00# ./ddlgen -SdatabaseServer:4100 -Uusername -PsecretPassword -TDB -NdatabaseName
U64: null: databaseName.dbo.firstTable
U64: null: databaseName.dbo.firstTable
at com.sybase.ddlgen.container.UserTableContainer.getDependentDDL(UserTableContainer.java:1065)
at com.sybase.ddlgen.container.UserTableContainer.open(UserTableContainer.java:1364)
at com.sybase.ddlgen.container.UserTableMetaContainer.open(UserTableMetaContainer.java:94)
at com.sybase.ddlgen.container.DDLBaseContainer.load(DDLBaseContainer.java:76)
at com.sybase.ddlgen.container.DatabaseContainer.addChildren(DatabaseContainer.java:552)
at com.sybase.ddlgen.container.DatabaseContainer.open(DatabaseContainer.java:104)
at com.sybase.ddlgen.container.DatabaseMetaContainer.open(DatabaseMetaContainer.java:114)
at com.sybase.ddlgen.DDLThread.run(DDLThread.java:89)
which wasn't very helpful. I keep thinking that there must be a nice Perlish way to do this, but I don't know what that would be.
You can also use the Perl-based dbschema.pl
http://www.isug.com/Sybase_FAQ/ASE/section9.html#9.3.2
use below command to get deffination
defncopy -P tester1 -S sqppdb2 -U pmestr -D ppdb2 -o tab4 ppdb2..tab4
Thanks
Download an evaluation version of Embarcadero DBArtisan and use its extract feature to get the DDL out.
You can turn Logging on in DBArtisan (Logfile ->Log SQL) and then see what SQL it's sending to Sybase to get the table DDL. Copy and paste the SQL in the logfile to a script that you run from the command line and that might work.
Apologies in advance if you are not using Windows...DBArtisan is Windows-only.
Another way of doing this is MyGeneration a code generator (like CodeSmith but open source) which uses templates to create code. That code could be anything you like - Sql, C# etc. I use Sql Server and I've used some of the freely available templates to create DDL as you specify, and automagically create NHibernate Mapping files too - brilliant.
ddlgen will give you what you require and works very well. You seem to be having an enviroment issue with Java. Try again and post the error that you have in it's entirety.
Related
Want a syntax where I can give my DB2 details like server name,user name,password and sql file which want to execute using batch file.
I found syntax like sqlplus,sqlcmd for oracle and sql server respectively but no luck for 'DB2'.
Pls help me in it.
Note that this is about DB2 on the IBM i platform (see comments).
For Windows, from a command prompt, type db2cmd, then from there run e.g. db2 connect to YOUR_DATABASE user YOUR_USER_ID then e.g. db2 -tf filename.sql
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002036.html
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0010410.html
IBM i Access Client Solutions (which I assume you have available to you, this part of its functionality being free of charge) has a command line option for this, e.g.
java -jar acsbundle.jar /SYSTEM=MYAS400 /PLUGIN=rss /file=\mysqlscript.sql /autorun=1
See ftp://ftp.software.ibm.com/as400/products/clientaccess/solutions/GettingStarted_en.html for more information (specifically section 9.1.31).
I think, this might help somebody in future, who is looking for solution,Just make sure you have Db2 Client installed & add following snippet in your batch file.
SET DB2CLP=DB20FADE
runas /noprofile /user:db2admin "db2cmd -c db2 create database MyDatabase && db2 connect to MyDatabase && db2 -tvmf db2_create_tables.sql"
I too faced many issues but after some research i came up with this solution, i hope it will help you/someone.
Well, I guess you didn't really search.
Db2 has several command line interfaces that can be and are used for batch processing. Clpplus even offers Oracle-like syntax support and compatibility. There is even a tool named db2batch that allows to process statements with lots of options.
I am using PostgreSQL
PostgreSQL 9.0.12, compiled by Visual C++ build 1500, 32-bit
I have two identical database on same server. I need to fetch data from a particular table from fist database and insert those data into other table in second database. I have read something about "EXTENSION" in postgres but I still don't get idea about how to use it.
So which is the better way to do it?
Any suggestion would help so much. Thank you.
first open
share/contribs/dblink.sql
it is the path where postgreSQL is installed.
when you open this file , you will find some operations. copy it and paste it to the query window of your database and execute.
In my case i have executed this operations on both database.
now you will be able to run following kind of code
select * from dblink('dbname=databasename port=5432; password=P#ssw0rd123','select "id" from "State"')
as P("id" bigint);
Is there any third party tool (free or paid) which could be useful in generating Entity Relationship Diagram from the views in SQL Server 2005/2008 or higher version?
For example,I have a view in my database and I wish to generate ER Diagram based on all the tables that are being referred in the view.
Let me know for any doubts
Thanks!
you can use a Java-based free tool named SchemaSpy. It basically works with any RDBMS as long as it has a JDBC connector.
I have discovered this while scratching my own itch, and also created a detailed post on it. Can be found here: http://blog.kmonsoor.com/generate-er-diagram-from-sql-database/
Summary:
First of all, your system should have Java runtime properly
installed. SchemaSpy is a .jar file. Get it:
http://sourceforge.net/projects/schemaspy/files/
JDBC connector to
you DB. Make sure to match your DBMS version.
Also, SchemaSpy
depends on GarphViz to generate the ER-diagrams, so you need to be
installed it on your system. http://www.graphviz.org/Download..php
target DB instance must be up & running
Now, this command will do the magic:
$ java -jar ./schemaSpy_5.0.0.jar -t pgsql -host 127.0.0.1:5432 -db your_database_name \
-u your_DB_user_name -p your_password -s public \
-dp ./database_specific.jdbc3.jar \
-o output_folder
There are a couple ways to do this, many outlined below. The easiest approach would be to use SQL Server's own diagrammer (described on the link below).
http://msdn.microsoft.com/en-us/library/aa224825(v=sql.80).aspx
Just do it in SQL Server Management Studio:
Connect your DB, open Object Explorer and right click your view and select "Design". This gives you the graphical view designer, which is a pretty good ER diagram of your view.
use mysql workbench. There are tools already provided to generate ER diagram directly from database.
I've been trying to figure how postgresql works for the last couple of days. There's something I don't get. Is there a way to see the data inside the tables graphically? Something similar to MySQL's phpMyadmin? Or can I only see the data by querying it?
Try pgadmin3. http://www.pgadmin.org/
If you are using a package manager on your machine like MacPorts, you can also download it using sudo port install pgadmin3.
Here are some example screenshots which will guide you to find where you can select "View Data".
Make sure your are connected to your postgresql server and the specific database you are interested in.
Then click into its hierarchy to open up public, which will contain another group named Tables, like this:-
There is a free program called pgAdmin that you can download from pgadmin.org.
A while back I needed to parse a bunch of Serve-U FTP log files and store them in a database so people could report on them. I ended up developing a small C# app to do the following:
Look for all files in a dir that have not been loaded into the db (there is a table of previously loaded files).
Open a file and load all the lines into a list.
Loop through that list and use RegEx to identify the kind of row (CONNECT, LOGIN, DISCONNECT, UPLOAD, DOWNLOAD, etc), parse it into a specific kind of object corresponding to the kind of row and add that obj to another List.
Loop through each of the different object lists and write each one to the associated database table.
Record that the file was successfully imported.
Wash, rinse, repeat.
It's ugly but it got the job done for the deadline we had.
The problem is that I'm in a DBA role and I'm not happy with running a compiled app as the solution to this problem. I'd prefer something more open and more DBA-oriented.
I could rewrite this in PowerShell but I'd prefer to develop an SSIS package. I couldn't find a good way to split input based on RegEx within SSIS the first time around and I wasn't familiar enough with SSIS. I'm digging into SSIS more now but still not finding what I need.
Does anybody have any suggestions about how I might approach a rewrite in SSIS?
I have to do something similar with Exchange logs. I have yet to find an easier solution utilizing an all SSIS solution. Having said that, here is what I do:
First I use logparser from Microsoft and the bulk copy functionality of sql2005
I copy the log files to a directory that I can work with them in.
I created a sql file that will parse the logs. It looks similar to this:
SELECT TO_Timestamp(REPLACE_STR(STRCAT(STRCAT(date,' '), time),' GMT',''),'yyyy-M-d h:m:s') as DateTime, [client-ip], [Client-hostname], [Partner-name], [Server-hostname], [server-IP], [Recipient-Address], [Event-ID], [MSGID], [Priority], [Recipient-Report-Status], [total-bytes], [Number-Recipients], TO_Timestamp(REPLACE_STR([Origination-time], ' GMT',''),'yyyy-M-d h:m:s') as [Origination Time], Encryption, [service-Version], [Linked-MSGID], [Message-Subject], [Sender-Address] INTO '%outfile%' FROM '%infile%' WHERE [Event-ID] IN (1027;1028)
I then run the previous sql with logparser:
logparser.exe file:c:\exchange\info\name_of_file_goes_here.sql?infile=c:\exchange\info\logs\*.log+outfile=c:\exchange\info\logs\name_of_file_goes_here.bcp -i:W3C -o:TSV
Which outputs a bcp file.
Then I bulk copy that bcp file into a premade database table in SQL server with this command:
bcp databasename.dbo.table in c:\exchange\info\logs\name_of_file_goes_here.bcp -c -t"\t" -T -F 2 -S server\instance -U userid -P password
Then I run queries against the table. If you can figure out how to automate this with SSIS, I'd be glad to hear what you did.