Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebird SQL Statement to Get the Table Definition

Tags:

sql

firebird

I am writing my own Firebird database browser using the ibpp library. Is there a way I can get the table definition using an SQL statement?

like image 286
Thomas Turner Avatar asked Jun 08 '12 08:06

Thomas Turner


People also ask

What does Firebird SQL do?

Firebird is a relational database offering many ANSI SQL standard features that runs on Linux, Windows, and a variety of Unix platforms. Firebird offers excellent concurrency, high performance, and powerful language support for stored procedures and triggers.

Does Firebird use SQL?

Firebird is an open-source SQL relational database management system that support Linux, Microsoft Windows, macOS and other Unix platforms.

How do you create a table in Firebird database?

The first example creates a primary key constraint PK_CUST using an index named IX_CUSTNO: create table customers ( custno int not null constraint pk_cust primary key using index ix_custno, ... This, however: create table customers ( custno int not null primary key using index ix_custno, ...

Is Firebird SQL free?

Firebird is a free, open-source database management system, but “free” does not mean that everything is permitted. The use of Firebird is governed by two licenses: the IPL (InterBase Public License) and the IDPL (Initial Developer's Public License).


1 Answers

Firebird does not support schemas, so there is no way you can get that information.

The closest thing might be the owner, which you can get by querying RDB$RELATIONS

Edit

A "schema" is a namespace inside a database. Apparently you are looking for the table definition, not the schema.

You can retrieve the colums of a table and their datatypes by querying RDB$FIELDS and RDB$RELATION_FIELDS:

select rf.rdb$relation_name as table_name, 
       rf.rdb$field_name as column_name,
       case f.rdb$field_type
         when 14 then 'CHAR'
         when 37 then 'VARCHAR'
         when 8 then 'INTEGER'
         ...
       end as data_type,
       f.rdb$field_length,
       f.rdb$field_scale
from rdb$fields f
  join rdb$relation_fields rf on rf.rdb$field_source = f.rdb$field_name
where rf.rdb$relation_name = 'FOOBAR'

The datatype is stored as an integer in the column RDB$FIELD. The full list of values in that column is documented in the Interbase Reference Guide: http://www.ibphoenix.com/files/60LangRef.zip (as are all other columns in that system table and all other system tables as well). You might need to go through all the update guides to check if there were any changes to the system tables since IB 6.0 (The Firebird manualy are a **reall* mess)

like image 148
a_horse_with_no_name Avatar answered Sep 18 '22 19:09

a_horse_with_no_name