[OracleDB] 超初心者サンプルスキーマ「SCOTT」の作成方法

こんにちは!(daikidomon)です。

Oracle Databaseのサンプルスキーマで「SCOTT」の作成方法を紹介します。

最初からデータベースを学ぶためのOracle Databaseで用意されている超初心者向けのスキーマなので、

これからデータベースを学びたい人は、ぜひこの記事を参考にしてみてください。

目次

SCOTTスキーマとは何か?

scottスキーマとは、

Oracle Databaseの初期バージョンの開発者である”Scott”さんから付けられた名前です。

またscottスキーマのパスワードは「tiger」で、

由来は”Scott”さんが飼っていた猫の名前から取ったそうです。

下が9i時代にマニュアルにあるSCOTTスキーマの説明になります。

History
At or near the beginning of Oracle, there was the scott schema. Oracle has used several sets of example tables to demonstrate technology over the years, including multiple variations of the scott schema and the popular Summit Sporting Goods schema.
By the end of 1999, however, the rich data types and complex objects available in Oracle8i Database far surpassed the demonstration ability of the simple objects available in the scott schema. So, to demonstrate the power of Oracle8i, Oracle built a whole set of interrelated schemas, each with its own level of complexity and product focus.

参考:Oracle 9iでのscott

SCOTTスキーマの作成

SCOTTスキーマの作成で簡単で以下のSQLを実行します。

$ sqlplus / as sysdba

SQL> @?/rdbms/admin/utlsampl.sql

SYSユーザになって「utlsampl.sql」を実行しましょう。

※今回はOracle Database12.2での動作確認を行っています。

ちなみにOracle Database10g以前にはSCOTTスキーマがデフォルトで作成されているそうです。

SCOTTスキーマを操作してみる

では実際にScottユーザにログインして操作してみましょう。 パスワードは「tiger」になります。

$ sqlplus scott/tiger

SQL> select table_name from user_tables;

TABLE_NAME
--------------------------------------------------------------------------------
EMP
DEPT
BONUS
SALGRADE

上記のようにテーブルとして、

  • EMP
  • DEPT
  • BONUS
  • SALGRADE

が作成されています。 またテーブルには以下の主キー外部キーが付与されています。

SQL> column constraint_name format a20
SQL> column table_name format a20
SQL> select CONSTRAINT_NAME,
2 CONSTRAINT_TYPE,
3 TABLE_NAME
4 from USER_CONSTRAINTS;

CONSTRAINT_NAME CON TABLE_NAME
-------------------- --- --------------------
PK_DEPT P DEPT
PK_EMP P EMP
FK_DEPTNO R EMP
よかったらシェアしてね!
  • URLをコピーしました!
目次