Firebird 5 のインストール,データベース作成,テーブル定義とレコード挿入(Windows 上)

Firebird 5(リレーショナルデータベース管理システム)のWindows上での導入と基本操作について説明する.wingetコマンドを用いてインストールし,環境変数の設定を行う.ISQL(対話型SQLツール)を使用してデータベースを作成し,テーブル定義とレコード挿入を行う.また,アカウント作成やパスワード変更などの管理タスクもgsecコマンドで実行可能である.データ型やSQL文の具体例も示している.

目次

  1. インストール前に決めておく事項
  2. Firebird のインストール(Windows 上)
  3. ISQL の起動と終了
  4. データベースの作成
  5. テーブル定義とレコード挿入
  6. アカウント(ユーザ名とパスワード)作成,パスワード変更

関連する外部ページ

利用条件などは利用者で確認すること.

謝辞:このページで紹介するソフトウェア等の作者に感謝する

インストール前に決めておく事項

Firebird 5 のインストール(Windows 上)

  1. Windows で,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
  2. 次のコマンドを実行

    次のコマンドは,Firebird 5をインストールし,パスを通すものである.

    winget install --location "c:\firebird50" FirebirdProject.Firebird.5
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\firebird50\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    
  3. sysdbaパスワードの設定.

    最初に,「cd c:\firebird50\bin」で,Firebirdのインストールディレクトリに移動する. 既定(デフォルト)のsysdbaパスワードは「masterkey」であり,これを使用して,gsec コマンドで,新しいsysdbaパスワードを設定している

    cd c:\firebird50
    gsec -user sysdba -pass masterkey -mo sysdba -pw 新しいパスワード
    

ISQL の起動と終了

データベースの作成

データベースを作成するために,SQL の create database コマンドを使用する.

  1. Firebird ISQL の起動

    ISQL を起動するには,Windows のメニューで,次のように操作する. 「スタート」 → 「Firebird 5.0 (x64)」 → 「Firebird ISQL Tool

  2. データベース生成

    utf8の場合

    create database 'testdb' default character set utf8;
    

    sjisの場合

    create database 'testdb' default character set sjis;
    
  3. show database;」で,データベースが生成されたことを確認
    show database;
    
  4. exit;」で終了.
    exit;
    

テーブル定義とレコード挿入

  1. Firebird ISQL の起動

    ISQL を起動するには,Windows のメニューで,次のように操作する. 「スタート」 → 「Firebird 5.0 (x64)」 → 「Firebird ISQL Tool

  2. connect 'testdb';」で,データベースを開く.
    connect 'testdb';
    
  3. SQL を用いたテーブル定義
    Firebird のデータ型 Char: 32767 bytes Varchar: 32767 bytes Smallint: 16 bits Integer: 32 bits BigInt: 64 bits DECIMAL: Float: 32 bits, 3.4x10^-38 to 3.4x10^38, 7 digit precision Double: 64 bits, 1.7x10^-308 to 1.7x10^308, 15 digit precision Timestamp: 64 bits, 1 Jan 100 to 28 Feb 32768. Date: 32 bits, 1 Jan 100. to 29 Feb 32768. Time: 32 bits, 00:00 to 23:59.9999 Blob: 32GB
    create table order_records (
        id            integer primary key not null,
        yy            integer not null CHECK ( yy > 2008 ),
        mm            integer not null CHECK ( mm >= 1 AND mm <= 12 ),
        dd            integer not null CHECK ( dd >= 1 AND dd <= 31 ),
        customer_name varchar(32) not null,
        product_name  varchar(32) not null,
        unit_price    real not null check ( unit_price > 0 ),
        qty           integer not null check ( qty > 0 ),
        created_at    timestamp not null,
        updated_at    timestamp,
        check ( ( unit_price * qty ) < 200000 ) );
    
  4. SQL を用いたレコード挿入
    insert into order_records values( 1, 2024, 7, 26, 'kaneko', 'orange A', 1.2, 10, current_timestamp, NULL );
    insert into order_records values( 2, 2024, 7, 26, 'miyamoto', 'Apple M', 2.5, 2, current_timestamp, NULL );
    insert into order_records values( 3, 2024, 7, 27, 'kaneko', 'orange B', 1.2, 8, current_timestamp, NULL );
    insert into order_records values( 4, 2024, 7, 28, 'miyamoto', 'Apple L', 3, 1, current_timestamp, NULL );
    
  5. 確認表示
    select * from order_records; 
    
  6. 更新し確認表示
    update order_records set unit_price = 11.2 where id = 1;
    select * from order_records;
    
  7. テーブル一覧の表示
    show tables;
    
  8. exit;」で終了.
    exit;
    

アカウント(ユーザ名とパスワード)作成,パスワード変更

アカウント(ユーザ名とパスワード)作成

"c:\firebird50\gsec" -user sysdba -pass masterkey -add testuser -pw hoge$#34

パスワードの変更

ユーザ testuser について, パスワードを hoge$#34 から newpass変更したいときの実行例

"c:\firebird50\gsec" -user testuser -pass hoge$#34 -mo testuser -pw newpass

データベース管理者のパスワードの変更

データベース管理者 sysdba のパスワードを hoGE9!#8に設定したいときの実行例

"c:\firebird50\gsec" -user sysdba -pass masterkey -mo sysdba -pw hoGE9!#8

【まとめ】 Firebird 5の導入から基本操作までを体系的に説明,データベース管理の基礎を示した.