Tool to Generate ER diagrams from Views in SQL Server - sql-server

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.

Related

db2 database creation

I installed db2 client in my system for personal use. I am not able to understand from where to create the database so that i can create tables on that db and play around with sql queries as of now.
This is totally related to my personal use and learning purpose.
Please inform how to create a dummy database and play around with it with db2 client?
Regards,
Are you on Windows? Are you using DB2 Express-C? I'm assuming you are, since you say this is for personal work.
After you have the DB2 binaries installed, you should have been prompted with the "DB2 First Steps" application, where you could have the application go through a GUI to create the database for you. If you missed it, you should be able to find it in your start menu with Start -> Programs -> IBM DB2 -> DB2COPY1 (Default) -> Set-up Tools -> First Steps.
If you prefer the command line, you can use the following:
First, determine if your installation created a default instance (on Windows, this will be called DB2) by using the db2ilist command. In the DB2 Command Window, if you're not on the instance you want to create a database in, you can switch with the following command:
set db2instance=DB2
Be sure to not include spaces around the equal sign.
Now, in order to create a database in the current instance, you use this command:
db2 create database mydatbase
For further reading, IBM has produced a Getting Started ebook, and I would highly recommend you check it out!
The DB2 client is just that - a client only. It does not include the database engine.
To create a database you have to install the server. The server includes the client portions.

Oracle public server

I want to learn about oracle, to try some queries and other SQL features of oracle data base, but don't want to install and mess with all realted issues. So my question is - is there any publicly available oracle server, to which I can connect through terminal and play with it?
I mean a service where I can register and some space would be allocated to my profile
Take a look at: http://apex.oracle.com/
The only thing I can think of is SQLFiddle: http://sqlfiddle.com/
But it won't let you have a "private" space. You need to re-create your schema each time (but you can bookmark your script which might be enough for you).
You could also try one of the pre-built virtual appliances - see
http://www.oracle.com/technetwork/community/developer-vm/index.html
If you need direct database access, you can run it in a Docker instance:
docker run -d -p 1521:1521 -p 8080:8080 alexeiled/docker-oracle-xe-11g
Then connect to it with sqlplus
sqlplus system/oracle#localhost:1521/xe
See here for more passwords, info on apex, etc.
Just came across this: Oracle Live SQL. It is browser based so nothing to install locally. But, you need to have an Oracle account.
Browser based SQL worksheet access to an Oracle database schema

Oracle: Extract Graphical Database Representation

How can I extract (reverse engineering) a graphical (schema) representation of an Oracle database (tables and their relationships; with colums and datatypes....). Are there (free) tools, which can do this?
I think the Oracle SQL Developer has no such feature...
There is a related Oracle tool, SQL Developer Data Modeler which does reverse engineering and it is free. Find out more.
Sql Developer does this (check the SQL Modeller option) and lots lots more. An amazingly good tool !
For a free tool I recommend schema spy, http://schemaspy.sourceforge.net/.
It needs Java Runtime.
Look to http://schemaspy.sourceforge.net/sample/relationships.html to see diagrams it generate.
This tool is also more suitable to automatic build scripts.
simple usage with oracle hr template is given below.
SET JDBC_ORACLE_JAR=C:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar
SET CONNECTION_USERNAME=hr
SET CONNECTION_PASSWORD=hr
SET TNS_DATABASE_NAME=orcl
SET SCHEMA_NAME=HR
SET TABLE_NAME='EMP'
SET OUTPUT_NAME=HR_EMP
java -jar schemaSpy_5.0.0.jar -dp %JDBC_ORACLE_JAR% -db %TNS_DATABASE_NAME% -o schemaOutput%OUTPUT_NAME% -u %CONNECTION_USERNAME% -p %CONNECTION_PASSWORD% -i %TABLE_NAME%.* -schemas %SCHEMA_NAME% -hq -noviews -loglevel severe
java -jar schemaSpy_5.0.0.jar -dp %JDBC_ORACLE_JAR% -db %TNS_DATABASE_NAME% -o schemaOutput%OUTPUT_NAME% -u %CONNECTION_USERNAME% -p %CONNECTION_PASSWORD% -schemas %SCHEMA_NAME% -hq -noviews -loglevel severe
First one will give you diagram with tables starting with EMP .
Second one will give you diagram with all tables in hr schema .
Adminer is an awesome PHP single file that should be able to do what you request. I tried only with MySQL, but Oracle it's supported as well.
I'm not aware of any free tools:
MS Visio can reverse engineer (professional/Premium)
TOAD an expensive tool but well worth it IMO

Generate sql script of db/sprocs/etc. via command line

Is it possible to generate sql scripts for my sql server 2005/8 database via the command line?
I want to automate the build process and part of it requires me to get the entire schema (tables/sprocs/etc) in a file.
Microsoft released a new tool last week called mssql-scripter. The tool is a Python-based, open source command line tool and you can find the official announcement here. Essentially, the scripter allows you to generate T-SQL scripts (DDL and DML) for your database/database object as a .sql file. It's the command line version of the 'Generate Scripts' wizard in SSMS. Here's a quick usage example to get you started (schema only is the default):
$ pip install mssql-scripter
# script the database schema and data piped to a file.
$ mssql-scripter -S localhost -d AdventureWorks -U sa > ./adventureworks.sql
More usage examples are on our GitHub page here: https://github.com/Microsoft/sql-xplat-cli/blob/dev/doc/usage_guide.md
There used to be an utility called SCPTXFR.EXE which was part of the standard SQL Server 7.0 and 2000 install.Its original purpose was as part of the upgrade process that allowed SQL Server 6.5 databases to be migrated to SQL Server 7.0 and 2000. However it is also very useful in a day-to-day environment, as it allows you to programmatically generate scheduled scripts of database objects.
Not sure if this will work for SQL 2005/2008. Check this document for full details of this utility.
Raj
I had to do something similar in a past project. I wrote a simple C# console application using Sql Server Management Objects. You can write code as simple as this (may need some tweaking):
Server myServer = new Server("name");
Database db = myServer.Databases["name"];
foreach (StoredProcedure sp in db.StoredProcedures)
{
File.WriteAllText(sp.Name, sp.TextBody);
}
I wrote a utility for this task, SMOscript.
It's based on the principle of SCPTXFR (which Raj mentioned), and also supports the new object types in SQL 2005 and 2008. Script generation is performed by the SMO library.
Powershell script + object Microsoft.SqlServer.Management.Smo.Scripter? See http://blogs.msdn.com/buckwoody/archive/2009/07/02/powershell-and-sql-server-script-all-tables.aspx for an example showing how to get started w/tables. You'd have to extend the idea to other objects.

Generating DDLs for Sybase tables and indexes

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.

Resources