<commit_before># Classes

It's easier to introduce OrientDB's basic concepts by outlining the Document Database API. It is more similar to Relational DBMS concepts and therefore a little more natural to follow for many developers. These basic concepts are shared between all of OrientDB's APIs: Document, Object, and Graph.

As with the relational DBMS, OrientDB has the concept of [records](Concepts.md#record) as an element of storage. There are different types of [records](Concepts.md#record), but for the next examples we will always use the [document](Concepts.md#document) type. A [document](Concepts.md#document) is composed of attributes and can belong to one [class](Concepts.md#class). Going forward we will also refer to the attributes with the terms "fields" and "properties".

The concept of [class](Concepts.md#class) is well known to those who program using object-oriented languages. Classes are also used in OrientDB as a type of data model according to certain rules. To learn more about Classes in general take a look at [Wikipedia](http://en.wikipedia.org/wiki/Class_in_object-oriented_programming).

To list all the configured classes, type the [`CLASSES`](Console-Command-Classes.md) command in the console:

<pre>
orientdb> <code class="lang-sql userinput">CLASSES</code>

CLASSES:
-------------------+-----------+-----------+
 NAME              | CLUSTERS  | RECORDS   |
-------------------+-----------+-----------+
 AbstractPerson    | -1        |         0 |
 Account           | 11        |      1126 |
 Actor             | 91        |         3 |
 Address           | 19        |       166 |
 Animal            | 17        |         0 |
 ....              | ....      |      .... |
 Whiz              | 14        |      1001 |
-------------------+-----------+-----------+
 TOTAL                               22775 |
-------------------------------------------+
</pre>

To create a new class, use the [`CREATE CLASS`](SQL-Create-Class.md) command:

<pre>
orientdb> <code class="lang-sql userinput">CREATE CLASS Student</code>

Class created successfully. Total classes in database now: 92
</pre>

OrientDB allows you to work in a schema-less mode, without defining properties. However, properties are mandatory if you define indexes or constraints. To create a new property use the [`CREATE PROPERTY`](SQL-Create-Property.md) command. Here is an example of creating three properties against the `Student` class:

<pre>
orientdb> <code class="lang-sql userinput">CREATE PROPERTY Student.name string</code>

Property created successfully with id=1


orientdb> <code class="lang-sql userinput">CREATE PROPERTY Student.surname string</code>

Property created successfully with id=2


orientdb> <code class="lang-sql userinput">CREATE PROPERTY Student.birthDate date</code>

Property created successfully with id=3
</pre>

To display the class `Student`, use the [`INFO CLASS`](Console-Command-Info-Class.md) command:

<pre>
orientdb> <code class="lang-sql userinput">INFO CLASS Student</code>

Class................: Student
Default cluster......: student (id=96)
Supported cluster ids: [96]
Properties:
-----------+--------+--------------+-----------+----------+----------+----+-----+
 NAME      | TYPE   | LINKED TYPE/ | MANDATORY | READONLY | NOT NULL |MIN |MAX |
           |        | CLASS        |           |          |          |    |     |
-----------+--------+--------------+-----------+----------+----------+----+-----+
 birthDate | DATE   | null         | false     | false    | false    |    |     |
 name      | STRING | null         | false     | false    | false    |    |     |
 surname   | STRING | null         | false     | false    | false    |    |     |
-----------+--------+--------------+-----------+----------+----------+----+-----+
</pre>

To add a constraint, use the [`ALTER CLASS`](SQL-Alter-Class.md) command. For example, let's specify that the `name` field should be at least 3 characters:

<pre>
orientdb> <code class="lang-sql userinput">ALTER PROPERTY Student.name MIN 3</code>

Property updated successfully
</pre>

To see all the records in a class, use the [`BROWSE CLASS`](Console-Command-Browse-Class.md) command:

<pre>
orientdb> <code class="lang-sql userinput">BROWSE CLASS OUser</code>
</pre>

In this case we are listing all of the users of the database. This is not particularly secure. You should further deepen the OrientDB [Security](Security.md) system, but for now `OUser` is a class like any other. For each query the console always shows us the number of the records in the result set and the [record's ID](Concepts.md#RecordID).

<pre>
orientdb> <code class="lang-sql userinput">BROWSE CLASS OUser</code>

---+------+-------+--------+-----------------------------------+--------+-------+
 # | @RID | @Class| name   | password                          | status | roles |
---+------+-------+--------+-----------------------------------+--------+-------+<commit_msg>Initial formatting on Getting Started Classes, revised introductory text.<commit_after># Classes

Multi-model support in the OrientDB engine provides a number of ways to approaching and understanding its basic concepts.  These concepts are clearest when viewed from the perspective of the Document Database API. Like many database management systems, OrientDB uses the [Record](Concepts.md#record) as an element of storage.  There are many types of records, but with the Document Database API records always use the [Document](Concepts.md#document) type.  Documents are formed by a set of key/value pairs, referred to as fields and properties, and can belong to a class.

The [Class](Concepts.md#class) is a concept drawn from the Object-oriented programming paradigm.  It is a type of data model that allows you to define certain rules for records that belong to it.  In the traditional Document database model, it is comparable to the collection, while in the Relational database model it is the table.

>For more information on classes in general, see [Wikipedia](http://en.wikipedia.org/wiki/Class_in_object-oriented_programming).


## Listing Classes

To list all the configured classes on your system, use the [`CLASSES`](Console-Command-Classes.md) command in the console:

<pre>
orientdb> <code class="lang-sql userinput">CLASSES</code>

CLASSES:
-------------------+------------+----------+-----------+
 NAME              | SUPERCLASS |CLUSTERS  | RECORDS   |
-------------------+------------+----------+-----------+
 AbstractPerson    |            | -1       |         0 |
 Account           |            | 11       |      1126 |
 Actor             |            | 91       |         3 |
 Address           |            | 19       |       166 |
 Animal            |            | 17       |         0 |
 ....              | ....       | ....     |      .... |
 Whiz              |            | 14       |      1001 |
-------------------+------------+----------+-----------+
 TOTAL                                           22775 |
-------------------------------------------------------+
</pre>




## Creating Classes



To create a new class, use the [`CREATE CLASS`](SQL-Create-Class.md) command:

<pre>
orientdb> <code class="lang-sql userinput">CREATE CLASS Student</code>

Class created successfully. Total classes in database now: 92
</pre>

### Adding Properties to a Class

OrientDB allows you to work in a schema-less mode, without defining properties. However, properties are mandatory if you define indexes or constraints. To create a new property use the [`CREATE PROPERTY`](SQL-Create-Property.md) command. Here is an example of creating three properties against the `Student` class:

<pre>
orientdb> <code class="lang-sql userinput">CREATE PROPERTY Student.name string</code>

Property created successfully with id=1


orientdb> <code class="lang-sql userinput">CREATE PROPERTY Student.surname string</code>

Property created successfully with id=2


orientdb> <code class="lang-sql userinput">CREATE PROPERTY Student.birthDate date</code>

Property created successfully with id=3
</pre>

### Displaying Class Information

To display the class `Student`, use the [`INFO CLASS`](Console-Command-Info-Class.md) command:

<pre>
orientdb> <code class="lang-sql userinput">INFO CLASS Student</code>

Class................: Student
Default cluster......: student (id=96)
Supported cluster ids: [96]
Properties:
-----------+--------+--------------+-----------+----------+----------+----+-----+
 NAME      | TYPE   | LINKED TYPE/ | MANDATORY | READONLY | NOT NULL |MIN |MAX |
           |        | CLASS        |           |          |          |    |     |
-----------+--------+--------------+-----------+----------+----------+----+-----+
 birthDate | DATE   | null         | false     | false    | false    |    |     |
 name      | STRING | null         | false     | false    | false    |    |     |
 surname   | STRING | null         | false     | false    | false    |    |     |
-----------+--------+--------------+-----------+----------+----------+----+-----+
</pre>

### Adding Constraints to Properties

To add a constraint, use the [`ALTER CLASS`](SQL-Alter-Class.md) command. For example, let's specify that the `name` field should be at least 3 characters:

<pre>
orientdb> <code class="lang-sql userinput">ALTER PROPERTY Student.name MIN 3</code>

Property updated successfully
</pre>

## Viewing Records in a Class

To see all the records in a class, use the [`BROWSE CLASS`](Console-Command-Browse-Class.md) command:

<pre>
orientdb> <code class="lang-sql userinput">BROWSE CLASS OUser</code>
</pre>

In this case we are listing all of the users of the database. This is not particularly secure. You should further deepen the OrientDB [Security](Security.md) system, but for now `OUser` is a class like any other. For each query the console always shows us the number of the records in the result set and the [record's ID](Concepts.md#RecordID).

<pre>
orientdb> <code class="lang-sql userinput">BROWSE CLASS OUser</code>

---+------+-------+--------+-----------------------------------+--------+-------+
 # | @RID | @Class| name   | password                          | status | roles |
---+------+-------+--------+-----------------------------------+--------+-------+
{'fraction_non_alphanumeric': 0.2024995118140988, 'fraction_numerical': 0.008006248779535248, 'mean_word_length': 1.9315970234688036, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7456668', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2537, 'n_words': 1007}