0

Hello I'm learning for my databases examination and in one exercise they asking for creating a table with a attribute which can only use values between 6 and 36. How do I solve it?

We used in the course always Oracle databases and not mysql.

Here is the original text of the exercise (in german language):

Erstellen Sie eine Tabelle PROJEKTE. Projekte haben einen Namen, eine Projektnummer, die Personalnummer eines Professors, der die Rolle des Projektleiters übernimmt, einen Starttermin und eine Laufzeit (ganze Zahlen zwischen 6 und 36).

2

Most likely, the intention is for you to create a table and a CHECK constraint on the table

CREATE TABLE foo (
  col1 integer check( col1 between 6 and 36 )
);

And a demonstration that it works

SQL> CREATE TABLE foo (
  2    col1 integer check( col1 between 6 and 36 )
  3  );

Table created.

SQL> insert into foo values( 5 );
insert into foo values( 5 )
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.SYS_C0047240) violated


SQL> insert into foo values( 37 );
insert into foo values( 37 )
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.SYS_C0047240) violated


SQL> insert into foo values( 12 );

1 row created.
  • 3
    @Kingalione: MySQL does not support check constraints (but won't tell you). If you are serious about learning SQL you should pick a better (more modern, closer to the standard) DBMS (such as Postgres) – a_horse_with_no_name Feb 1 '14 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.