Oracle PL/SQL Tutorial/Table/Comment

Материал из SQL эксперт

Перейти к: навигация, поиск

Add a comment to the myTable.id column

SQL>
SQL> -- create demo table
SQL> CREATE TABLE myTable(
  2    id           NUMBER(2),
  3    value        NUMBER(6,2)
  4  )
  5  /
TABLE created.
SQL>
SQL> -- prepare data
SQL> INSERT INTO myTable(ID,  value)VALUES (1,9)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (2,2.11)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (3,3.44)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (4,-4.21)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (5,10)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (6,3)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (7,-5.88)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (8,123.45)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (9,98.23)
  2  /
1 row created.
SQL>
SQL> SELECT * FROM myTable
  2  /
        ID      VALUE
---------- ----------
         1          9
         2       2.11
         3       3.44
         4      -4.21
         5         10
         6          3
         7      -5.88
         8     123.45
         9      98.23
9 rows selected.
SQL>
SQL>
SQL>
SQL> COMMENT ON COLUMN myTable.id IS
  2  "id stores the id";
Comment created.
SQL>
SQL>
SQL> -- clean the table
SQL> DROP TABLE myTable
  2  /
TABLE dropped.
SQL>
SQL>


Adding a Comment to a Table

A comment can help you remember what the table or column is used for.

You add a comment to a table or column using the COMMENT statement.



SQL> -- create demo table
SQL> CREATE TABLE myTable(
  2    id           NUMBER(2),
  3    value        NUMBER(6,2)
  4  )
  5  /
TABLE created.
SQL>
SQL> -- prepare data
SQL> INSERT INTO myTable(ID,  value)VALUES (1,9)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (2,2.11)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (3,3.44)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (4,-4.21)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (5,10)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (6,3)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (7,-5.88)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (8,123.45)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (9,98.23)
  2  /
1 row created.
SQL>
SQL> SELECT * FROM myTable
  2  /
        ID      VALUE
---------- ----------
         1          9
         2       2.11
         3       3.44
         4      -4.21
         5         10
         6          3
         7      -5.88
         8     123.45
         9      98.23
9 rows selected.
SQL>
SQL>
SQL>
SQL> COMMENT ON TABLE myTable IS
  2  "myTable is my table";
Comment created.
SQL>
SQL>
SQL> -- clean the table
SQL> DROP TABLE myTable
  2  /
TABLE dropped.
SQL>
SQL>


Getting Table Comments

You can get the comments on your tables using user_tab_comments.



SQL> -- create demo table
SQL> CREATE TABLE myTable(
  2    id           NUMBER(2),
  3    value        NUMBER(6,2)
  4  )
  5  /
TABLE created.
SQL>
SQL> -- prepare data
SQL> INSERT INTO myTable(ID,  value)VALUES (1,9)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (2,2.11)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (3,3.44)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (4,-4.21)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (5,10)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (6,3)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (7,-5.88)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (8,123.45)
  2  /
1 row created.
SQL> INSERT INTO myTable(ID,  value)VALUES (9,98.23)
  2  /
1 row created.
SQL>
SQL> SELECT * FROM myTable
  2  /
        ID      VALUE
---------- ----------
         1          9
         2       2.11
         3       3.44
         4      -4.21
         5         10
         6          3
         7      -5.88
         8     123.45
         9      98.23
9 rows selected.
SQL>
SQL>
SQL>
SQL> COMMENT ON TABLE myTable IS
  2  "myTable is my table";
Comment created.
SQL>
SQL> SELECT *
  2  FROM user_tab_comments
  3  WHERE table_name = "MYTABLE";
TABLE_NAME                     TABLE_TYPE       COMMENTS
------------------------------------------------
MYTABLE                        TABLE            myTable IS my TABLE
 
SQL>
SQL> -- clean the table
SQL> DROP TABLE myTable
  2  /
TABLE dropped.
SQL>
SQL>
SQL>