cf) [[Firebird 2.5 Release Notes:http://www.firebirdsql.org/file/documentation/release_notes/html/rlsnotes251.html#rnfb25-ddl-crtdb-diffile]]

(目次つける・・・)

* Data Definition Language (DDL) [#ydf93c47]
** Visibility of Procedure Definition Changes on Classic [#wda3de0e]

One such change addressed the problem of the visibility of altered stored procedures to other connections to the Classic server.

Classic サーバーにおいて、ほかの接続でstored procedureを修正すると、見えなくなる問題への対処。

Now, such changes are made visible to the entire server as soon as the modifying transaction has completed its commit.

修正しているトランザクションがコミットを完了させるとすぐ、全体のサーバーに可視性の変更が通知される

** CREATE/ALTER/DROP USER [#w97b76bc]

In v.2.5, Firebird finally has syntax to enable user accounts on the server to be managed by submitting SQL statements when logged in to a regular database.

Firebird 2.5で、正規のデータベースにログインしたとき、提出するSQL文によって管理されるユーザーアカウントを有効にする構文が追加された。

The CREATE USER and CREATE USER statements also include the parameters GRANT ADMIN ROLE and REVOKE ADMIN ROLE to enable a user with SYSDBA privileges user to grant the RDB$ADMIN role in the security database to an ordinary user.

CREATE USER、CREATE USERは、通常のユーザーにセキュリティデータベースのRDB$ADMINロールを付与するために、SYSDBA権限を持つユーザーを有効にするパラメータ、GRANT ADMIN ROLE(無効にするパラメータ、REVOKE ADMIN ROLE)を持っている。

For the usage description and a full overview of the RDB$ADMIN role, refer to the topic New RDB$ADMIN System Role in the Administrative Features chapter.

RDB$ADMINの概要や使用例については、 [[Administrative FeaturesのNew RDB$ADMIN System Role>Firebird 2.5 メタデータ(未整理)]] を参照。

Syntax Patterns

The SYSDBA, or a user with SYSDBA privileges in both the current database and the security database, can add a new user:

SYSDBAまたはSYSDBA権限を持つユーザーは、データベース(セキュリティデータベース含む)に新しいユーザーを追加する事が出来る。

CREATE USER <username> {PASSWORD 'password'}
  [FIRSTNAME 'firstname']
  [MIDDLENAME 'middlename']
  [LASTNAME 'lastname']
  [GRANT ADMIN ROLE];
 
Note

The PASSWORD clause is required when creating a new user.

PASSWORD句は必須項目。

It should be the initial password for that new user. The user can change it later, using ALTER USER.

その新規ユーザーのパスワードの初期値となる。ユーザーは後でALTER USERでパスワードを変更する事が出来る。

The SYSDBA, or a user with SYSDBA privileges in both the current database and the security database, can change one or more of the password and proper name attributes of an existing user.

SYSDBAまたはSYSDBA権限を持つユーザーは、データベース(セキュリティデータベース含む)に登録されているユーザーの属性(名前、パスワード等)を変更する事が出来る。

Non-privileged users can use this statement to alter only their own attributes.

SYSDBA権限を持たないユーザーは、自身の属性のみを変更する事が出来る。

ALTER USER <username>
  [PASSWORD 'password']
  [FIRSTNAME 'firstname']
  [MIDDLENAME 'middlename']
  [LASTNAME 'lastname']
  [{GRANT | REVOKE} ADMIN ROLE];
 
Note

At least one of the optional parameters must be present.

いずれか一つのパラメータを指定しなければならない。

ALTER USER does not allow the <username> to be changed.

ALTER USERはユーザー名を変更する事が出来ない。

If a different <username> is required, the old one should be deleted (dropped) and a new one created.

ユーザー名を変更したい場合は、一度そのユーザーを削除し、別途新たにユーザーを作成する。


The SYSDBA, or a user with SYSDBA privileges in both the current database and the security database, can delete a user:

SYSDBAまたはSYSDBA権限を持つユーザーは、データベース(セキュリティデータベース含む)に登録されているユーザーを削除する事が出来る。

DROP USER <username>;
 
Restrictions

CREATE USER and DROP USER statements and GRANT | REVOKE ADMIN ROLE are available only for the SYSDBA, or a user that has acquired the RDB$ADMIN role in both the current database and the security database.

CREATE USER、DROP USER、GRANT / REVOKE ADMIN ROLEはSYSDBAまたはSYSDBA権限を持つユーザーのみ使用する事が出来る。

An ordinary user can ALTER his own password and elements of his proper name.

通常のユーザーは自身の属性を変更する事が出来る

An attempt to modify another user will fail.

ほかのユーザーの属性の変更は失敗する。

Examples

SYSDBA or a user with equivalent privileges in both the current database and the security database, can do:

CREATE USER alex PASSWORD 'test';

ALTER USER alex FIRSTNAME 'Alex' LASTNAME 'Peshkov';

ALTER USER alex PASSWORD 'IdQfA';
 


** Syntaxes for Altering Views [#f1c9314a]

Previously, in order to alter a view definition, it was necessary to save the view definition off-line somewhere and drop the view, before recreating it with its changes.

過去のバージョンでは、View定義を変更するために、一度削除してから再作成する必要があった。

This made things very cumbersome, especially if there were dependencies.

依存性を持つ場合、この操作は重荷となっていた。

V.2.5 introduces syntaxes for ALTER VIEW and CREATE OR ALTER VIEW.

Firebird 2.5では、ALTER VIEW、CREATE OR ALTER VIEWが追加された。


*** ALTER VIEW [#m06755c0]

ALTER VIEW enables a view definition to be altered without the need to recreate (drop and create) the old version of the view and all of its dependencies.

ALTER VIEWは変更前のVIEWの再生成(DROP、CREATE)なしに変更された定義を有効にする。

*** CREATE OR ALTER VIEW [#vd93570b]

With CREATE OR ALTER VIEW, the view definition will be altered (as with ALTER VIEW) if it exists, or created if it does not exist.

CREATE OR ALTER VIEWは、まだ未作成であれば新規にVIEWを作成し、作成済みであれば新たな定義でVIEWを変更する。

Syntax Pattern

{create [ or alter ] | alter } view <view_name>
  [ ( <field list> ) ]
as <select statement>
 
Example

create table users (
    id integer,
    name varchar(20),
    passwd varchar(20)
);

create view v_users as
    select name from users;

alter view v_users (id, name) as
    select id, name from users;
 

*** Extensions for CREATE VIEW [#wce2302e]

The following extensions have been added for CREATE VIEW.

CREATE VIEWに以下の拡張が加えられた。

Specify Stored Procedure in FROM Clause

FROM句にStored Procedureを指定する事が出来る。

Adriano dos Santos Fernandes
Tracker reference CORE-886.

A selectable stored procedure can now be specified in the FROM clause of a view definition.

Example

    create view a_view as
    select * from a_procedure(current_date);

 
Create UNION View Without Column List

Dmitry Yemanov
Tracker reference CORE-1402.

The column list can now be omitted from CREATE VIEW when the set is defined by a UNION.

結果セットがUNION句を用いて定義されるとき、CREATE VIEWで列宣言を省略する事が出来る。

Example

 recreate view V1 as
   select d.rdb$relation_id from rdb$database d
   union all
   select d.rdb$relation_id from rdb$database d

 recreate view V2 as
   select d.rdb$relation_id as q from rdb$database d
   union all
   select d.rdb$relation_id as w from rdb$database d
 

Inferred Column Names

Adriano dos Santos Fernandes
Tracker reference CORE-2424.

CREATE VIEW now has the capability to infer column names for views involving a GROUP BY clause or a derived table.

CREATE VIEWはGROUP BY句やサブクエリから、列名を推論する事が出来る。

Example

 create view V as
   select d.rdb$relation_id from rdb$database d
     group by d.rdb$relation_id

 create view V as
    select a from (select 1 a from rdb$database);
 

** ALTER Mechanism for Computed Columns [#t70293ed]

A column defined as COMPUTED BY <expression> can now be altered using the ALTER TABLE...ALTER COLUMN syntax.

COMPUTED BY <式>として定義された列は、ALTER TABLE...ALTER COLUMNで変更する事が出来る。

This feature can be used only to change the <expression> element of the column definition to a different expression.

この機能は列定義の式を変更する事のみ可能。

It cannot convert a computed column to non-computed or vice versa.

この構文は、計算列を通常の列定義に変更、またはその逆を行う事はできない。

Syntax Pattern

alter table <table-name>
  alter <computed-column-name>
  [type <data-type>]
  COMPUTED BY (<expression>);
 
Examples

create table test (
  n integer,
  dn computed by (n * 2)
);
commit;
alter table test
  alter dn computed by (n + n);
 


** Extensions for SQL Permissions [#o294b9d8]

Alex Peshkov
The following extensions have been implemented in the area of SQL permissions (privileges).

*** GRANTED BY Clause [#ca1466df]

A GRANTED BY (or its alternative, AS) clause can now be optionally included in GRANT and REVOKE statements, enabling the grantor to be a user other than the CURRENT_USER (the default).

GRANT / REVOKEにGRANTED BY句が追加された。これはほかのユーザーに権限を付与するものである。

Syntax Pattern

grant <right> to <object>
  [ { granted by | as } [ user ] <username> ]
--
revoke <right> from <object>
  [ { granted by | as } [ user ] <username> ]
 
Tip


  { granted by | as }
 

GRANTED BY and AS are equivalent.

GRANTED BYとGRANTED ASは等価。

GRANTED BY is the form recommended by the SQL standard.

GRANTED BYはSQL標準化されている。

We support AS for compatibility with some other servers (Informix, for example).

ほかのDBサーバー(Infomix)で用いられるGRANTED ASもサポートしている。

Example

Logged in as SYSDBA:

SYSDBAでログインして、

create role r1; -- SYSDBA owns the role
  /* next, SYSDBA grants the role to user1
     with the power to grant it to others */
grant r1 to user1 with admin option;
  /* SYSDBA uses GRANTED BY to exercise
     user1's ADMIN OPTION */
grant r1 to public granted by user1;
 
In isql, we look at the effects:

isqlの場合:

  SQL>show grant;
  /* Grant permissions for this database */
  GRANT R1 TO PUBLIC GRANTED BY USER1
  GRANT R1 TO USER1 WITH ADMIN OPTION
  SQL>
 


*** ALTER ROLE [#u47e4fad]

Tracker reference CORE-1660.

The new ALTER ROLE statement has a specialised function to control the assignment of SYSDBA permissions to Windows administrators during trusted authentication.

追加されたALTER ROLEは信頼された認証の間Windowsの管理者にSYSDBA権限の割り当てを制御するための特別な機能を有する。

It has no other purpose currently.

現在、ほかの機能はない。

Note

For the usage description of ALTER ROLE and a full overview of the RDB$ADMIN role, refer to the topic New RDB$ADMIN System Role in the Administrative Features chapter.

ALTER ROLEの使用例やRDB$ADMINの概要は [[Administrative FeaturesのNew RDB$ADMIN System Role>Firebird 2.5 メタデータ(未整理)]] を参照。

*** REVOKE ALL [#l6d518ab]

Tracker reference CORE-2113.

When a user is removed from the security database or another authentication source, such as the operating system ACL, any associated cleanup of SQL privileges in databases has to be performed manually.

ユーザーがセキュリティデータベースやほかの認証ソース(OSのACL等)から削除される場合、データベース内の関連するSQL特権のクリーンナップを書道で実行しなければならない。

This extension adds the capability to revoke all privileges in one stroke from a particular user or role.

この機能を使う事で、特定のユーザーやロールからワンステップですべての特権を削除する事が出来る。

Syntax Pattern

REVOKE ALL ON ALL FROM { <user list> | <role list> }
 
Example

Logged in as SYSDBA:

# gsec -del guest
# isql employee
fbs bin # ./isql employee
Database:  employee
SQL> REVOKE ALL ON ALL FROM USER guest;
SQL>
 

*** Default COLLATION Attribute for a Database [#r9c61e9f]

Adriano dos Santos Fernandes
Tracker references CORE-1737 and CORE-1803.

An ODS 11.2 or higher database can now have a default COLLATION attribute associated with the default character set,

ODS 11,2以降のバージョンは、規定のキャラクタセットに関連づけられたCOLLATION属性を持っている。

enabling all text column, domain and variable definitions to be created with the same collation order unless a COLLATE clause for a different collation is specified.

これは、すべてのテキスト形式の列、ドメイン、変数宣言が同じCOLLATIONで作成されるようになる(異なるCOLLATIONが指定された場合を除く)

The COLLATION clause is optional. If it is omitted, the default collation order for the character set is used.

COLLATION句はオプション。COLLATIONが指定されない場合、キャラクタセットについての規定の文字照合順序が使われる。

Tip

Note also that the default collation order for a character set used in a database can now also be changed, thanks to the introduction of syntax for ALTER CHARACTER SET.

データベースに使用されるキャラクタセットについての規定の文字照合順序は、ALTER CHARACTER SETで変更する事が出来得る。

Syntax Pattern

create database <file name>
    [ page_size <page size> ]
    [ length = <length> ]
    [ user <user name> ]
    [ password <user password> ]
    [ set names <charset name> ]
    [ default character set <charset name>
       [ [ collation <collation name> ] ]
    [ difference file <file name> ]
 
Note

The parameter DIFFERENCE FILE is not a new one for CREATE DATABASE.

CREATE DATABASEのパラメータ:DIFFERENCE FILEは、別段新しいものではない。

 It was quietly introduced in association with the nBackup utility in V.2.0 and has been lurking undocumented for three years.

nBackup 2.0の導入の際に追加されている。

For more information, see Evolution of CREATE DATABASE at the end of this chapter.

詳細は、この章の最後のEvolution of CREATE DATABASE参照

Example

create database 'test.fdb'
    default character set win1252
    collation win_ptbr;
 

*** ALTER CHARACTER SET Command [#db89c5df]

New syntax introduced in this version, enabling the default collation for a character set to be set for a database.

このバージョンから、データベース内のキャラクタセットの規定の文字照合順序を変更する事が出来る。

The default collation is used when table columns are created with a given character set (explicitly, through a CHARACTER SET clause in the column or domain definition, or implicitly, through the default character set attribute of the database) and no COLLATION clause is specified.

テーブルの各列にキャラクタセットが与えられて作られるとき(明示的に各列やドメインにCHARACTER SET句を指定して。またはデータベスの規定のキャラクタセットから暗黙的に。)、規定の文字照会順序が使われる

Note

String constants also use the default collation of the connection character set.

文字列定数もまた、接続時に指定されるキャラクタセットの規定の文字照会順序が使われる。

The character set and collation of existing columns are not affected by ALTER CHARACTER SET changes.

既に作成済みのテーブル列に指定されたキャラクタセットやCOLLATIONは、ALTER CHARACTER SETの変更の影響されない。

Syntax Pattern

ALTER CHARACTER SET <charset_name>
    SET DEFAULT COLLATION <collation_name>
 
Example

create database 'people.fdb'
  default character set win1252;

alter character set win1252
  set default collation win_ptbr;

create table person (
  id integer,
  name varchar(50)  /* will use the database default
                       character set and the win1252
                       default collation */
);

insert into person
  values (1, 'adriano');
insert into person
  values (2, 'ADRIANO');

/* will retrieve both records
   because win_ptbr is case insensitive */
select * from person where name like 'A%';
 
Tip

Another improvement allows the current value of RDB$DEFAULT_COLLATE_NAME in the system table RDB$CHARACTER_SETS to survive the backup/restore cycle.

backup/restoreの際、システムテーブル:RDB$CHARACTER_SETSのRDB$DEFAULT_COLLATE_NAMEの値を見る。

** Evolution of CREATE DATABASE [#meae0d3a]

DDL support for the database header attributes introduced to register and change the nBackup states has been evolving since Firebird 2.0.

nBackupの状態を登録したり変更するために導入されたデータベースヘッダ属性のDDLサポートが、Firebird 2.0で進化した。

Users of nBackup will be familiar with the ALTER DATABASE statements to begin and end the storage of the “delta” data, in a file apart from the main database, during a full nBackup.

nBackupのユーザーは、nBackupによるフルバックアップの間、メインデータベースから切り離されるファイルにおいて、差分データストレージを開始したり終了したりするために、ALTER DATABASEによく精通している。
(訳注:イミフ)

*** Naming the Delta File for nBackup [#udc17591]

ALTER DATABASE also has another argument that allows you to set the name that will be used for the file that stores the delta data.

ALTER DATABASEはまた、差分データを保存するファイル名を指定するためのパラメータも持っている。

To quote from Paul Vinkenoog's excellent manual for nBackup:

Paul VinkenoogのnBackupのマニュアルより引用。

By default, the delta file lives in the same directory as the database itself.

デフォルトで、差分ファイルはデータベースと同じディレクトリに置かれる。

It also has the same name as the database file, but with .delta appended.

差分ファイルのファイル名はデータベースファイル名 + .delta。

There is usually no reason to change this, but it can be done if need be—though not via nbackup itself.

nbackupを使わないのであれば、差分ファイルのファイル名を変更する事は大して問題では無い。

Make a connection to the database with any client that allows you to enter your own SQL statements and give the command:

すべてのクライアントでデータベースへの接続して、以下の文を実行する。

alter database
  add difference file 'path-and-filename'

The custom delta file specification is persistent in the database; it is stored in the system table RDB$FILES.

カスタムの差分ファイルの仕様は、システムテーブル:RDB$FILESに保存される。

To revert to the default behaviour, issue the following statement:

規定の挙動に復帰したい場合、以下の文を実行する。

alter database
  drop difference file
 
Those who are still curious may study the details in the V.2.0 release notes or in the nBackup manual.

詳細について知りたい人は、nBackup 2.0のマニュアルのリリースノート参照。


*** The DIFFERENCE FILE Argument for CREATE DATABASE [#q240c965]

C. Valderrama

In Firebird 2.0, syntax for prescribing a custom name for the delta file appeared as an extra, optional argument for CREATE DATABASE.

Firebird 2.0において、CREATE DATABASEのパラメータに、割り増し分として追加された差分ファイルに名前を付けるための構文が追加された。

You can observe its placement in the syntax pattern given above for the topic Default COLLATION Attribute for a Database.

「Default COLLATION Attribute for a Database」の章に示した構文で、その配置を観察する事が出来る。

As with ALTER DATABASE, the keyword for the argument is DIFFERENCE FILE and the argument is a valid file specification.

ALTER DATABASEと同様に、パラメータ名はDIFFERENCE FILE、値には正しいファイル名を指定する。

It allows you to specify a custom name for the delta file that will be created whenever ALTER DATABASE BEGIN BACKUP is called, or when the equivalent nBackup shell command is invoked.

ALTER DATABASE BEGIN BACKUPが実行された際に、または同等のnBackupコマンドが実行された際に、いつも作成される差分ファイルに対して名前を指定する事が出来る。

Examples of Usage

  ]..\bin> isql -user sysdba -pass masterke

 Use CONNECT or CREATE DATABASE to specify a database
 SQL> create database 'ticks' difference file 'jaguar';
 SQL> shell dir jaguar;
 Volume in drive F is Firebird
 Volume Serial Number is BCD9-4211

 Directory of ..\bin

 File Not Found
 
This is correct, we only defined the file name.

これはファイル名を定義しただけである。

Now it will be used:

使用する際は、

 SQL> alter database begin backup;
 SQL> shell dir jaguar;
 Volume in drive F is Firebird
 Volume Serial Number is BCD9-4211

 Directory of ..\bin

 10-11-2009  00:59             8.192 jaguar
                1 File(s)          8.192 bytes
                0 Dir(s)  16.617.979.904 bytes free

 SQL> alter database end backup;
 SQL> shell dir jaguar;
 Volume in drive F is Firebird
 Volume Serial Number is BCD9-4211

 Directory of ..\bin

 SQL> drop database;
 SQL> ˆZ
 
Since the argument is a file name, it goes inside single quotes.

パラメータはファイル名なので、シングルクォーテーションでくくること。

Double-quotes are not valid:
the statement will fail and return a confusing error message.

ダブルクォーテーションでくくったときは、エラーメッセージを吐いて、実行は失敗する

 ]..\bin> isql -user sysdba -pass master key

 Use CONNECT or CREATE DATABASE to specify a database
 SQL> create database 'ticks' DIFFERENCE FILE 'jaguar';
 SQL> alter database add difference file 'leopard';

 Statement failed, SQLCODE = -607
 unsuccessful metadata update
 -Difference file is already defined
 
The message is correct. Even though the delta was deleted by the ALTER DATABASE END BACKUP call, the name of the difference file is stored persistently and only one may exist.

ALTER DATABASE END BACKUPを実行すると、差分ファイルは削除されるが、差分ファイル名は保持され、ただ一つのみ存在する。

 SQL> alter database drop difference file;
 SQL> alter database begin backup;
 
This does not break anything, because the engine will rescue the situation and create the delta using the default mechanism.

データベースエンジンが規定の処理を行って差分ファイルを再作成するため、これは何も壊さない。

 SQL> alter database add difference file 'leopard';
 SQL> alter database begin backup;
 SQL> alter database drop difference file;

 Statement failed, SQLCODE = -607
 unsuccessful metadata update
 -Cannot change difference file name while database is in backup mode
 
This is correct validation.


 SQL> alter database end backup;
 SQL> drop database;
 SQL> ˆZ