wwwsqldesigner – mockup tool for DBAs
What do you need from database modelling tool?
If you need a full-blown enterprise-class modelling tool - OK, I understand, go and get one.
If you don't need diagramming on design stage (or all developers in your team are play-chess-in-my-mind types of guys), go and write SQL DDL. It's fun.
If you are still here, you might think - as I do - that:
- in early stages of database development, diagrams are often needed as a modelling and communication tool;
- Relational database is, after all, composed from a set of basic elements, constrained with basic rules;
- Modelling can be complex, but this should not mean: complicated! Simplicity in all aspects is what you want.
If so, you might be interested in wwwsqldesigner.
The tool is html+javascript+xml+slt, with some backend in php. It can
- draw and create database schemas directly in browser
- create tables and attributes
- create constraints (PK, UNIQUE, FK)
- create single or multifield indexes
- add comments on tables and attributes
- print, save, load diagrams
- SQL export (generate DDL)
- XML export/import (xml is the native format of wwwsqldesigner)
- reverse engineering (import schema from database)
- export implemented as XSLT transforms, so you can fix it (xslt is easy)
Here is demo installation. And here's my local install. I am testing this tool with PostgreSQL (both as a backend, and as a model target), and it works most of the time.
Note: If you want to test it on your own webserver, please make sure that you take fresh SVN checkout. It has several improvements over last packaged version.
I do not claim it's ultimate design tool. No, this is all about early database design.
czego _nie_ robić z bazami danych
Stare ale jare:
10 Things You Shouldn't Do with SQL Server (Data Access Developer "Don'ts").
Dotyczy .NET i MS SQL ale większość opisanych problemów jest niezależne od konkretnego produktu.
column number as column alias in postgres
I have seen such queries many times:
SELECT foo, bar, (some long and complicated SQL subexpression), count(*)
FROM somewhere
GROUP BY foo,bar, (some long and complicated SQL subexpression)
ORDER BY count(*) DESC
This has some drawbacks:
- you have to repeat exactly the same expression two times, which makes query longer
- it is easier to make a mistake while editing the subexpression
Did you know there's a neat shortcut for this in postgres?
SELECT foo, bar, (some long and complicated SQL subexpression), count(*)
FROM somewhere
GROUP BY 1,2,3
ORDER BY 4 DESC
This is known as column number aliases.
I have no idea if this comes from SQL standard or not.
But it saves me quite a lot of typing :)
I know it works at least in postgresql, mysql and informix.
Does it work in your database, too?
SQL przyszłości
Funkcje odpytywania tekstów w standardzie SQL
Ponieważ w pracy zajmuję się ostatnio trochę wyszukiwaniem pełnotekstowym (zwłaszcza dodatkiem tsearch2 do PostgreSQL), zastanawiałem się, czy doczekamy się kiedyś powszechnego standardu SQL dla odpytywania tekstów.
Tak żeby znający SQL człowiek, który podchodzi do swojego pięknego nowiutkiego "wypasionego" serwera nie musiał się zastanawiać co napisać, aby zmusić go do czarnej roboty.
Okazuje się, że już od jakiegoś czasu istnieje standard SQL/MM, który m.in. opisuje rozszerzenia pełnotekstowe.
Podaję przykłady zapytań, bo mówią same za siebie.
Tworzymy tabelę z polem pełnotekstowym:
CREATE TABLE dokumenty (
id INTEGER,
body FULLTEXT
)
Szukamy dokumentów, w których wyraz brzmiący podobnie do parboiled pojawia się w tym samym zdaniu, co słowo rice:
SELECT id
FROM dokumenty
WHERE body.CONTAINS(
' SOUNDS LIKE "parboiled"
IN SAME SENTENCE AS "rice" '
)
Szukamy dokumentów zawierających terminy bliskoznaczne do kontrola błędów (np. obsługa wyjątków):
SELECT id
FROM dokumenty
WHERE body.CONTAINS(
' THESAURUS "informatyka" EXPAND SYNONYM TERM OF "kontrola błędów" '
)
Standard definiuje też konstrukcje, których implementacja jest co najmniej nietrywialna:
SELECT id FROM dokumenty
WHERE body.CONTAINS( ' IS ABOUT "analiza leksykalna" ' )
ORDER BY body.SCORE( ' IS ABOUT "analiza leksykalna" ' )
Ładne, prawda? No w każdym razie dla mnie wygląda to bardzo sympatycznie.
Zachęcam do zerknięcia na cały dokument, jest do pobrania na stronie www.wiscorp.com.
Jednak nie wpadajmy w euforię.
Po pierwsze, SQL/MM Full-Text na razie jest tylko w ułamkowej części implementowany przez niektóre silniki bazodanowe.
Po drugie, relacyjne bazy danych mają swoje ograniczenia. Widoczne są one także na polu wyszukiwania "ze zrozumieniem" - bo w sumie do tego dążymy jak się chwilę zastanowić. Pisze o tym np. Curt Monash w artykule Relational DBMS versus text data.