0

A collection of puzzles is classified as 'easy', 'moderate' or 'challenging'. Each puzzle belongs to exactly one class. Here is a simplified version of the puzzle relation:

Student{puzzle_number:integer, description:text, class:text}

Write an SQL definition for this relation. Your definition should include a primary key constraint on puzzle_number and a check constraint at table level to enforce the requirement that the value of 'class' is one of 'easy', 'moderate' or 'challenging'

I am unsure what is meant by an SQL definition? Does it mean a create table statements?

Chid
  • 45
  • 1
  • 8
  • Can you give us the definition you have so far so we can see what you wrote and try and improve your answer please ? – Sandy Jan 11 '17 at 22:59
  • 1
    DML (Data Markup Language) vs DDL (Data ***Definition*** Language) http://stackoverflow.com/questions/2578194/what-is-ddl-and-dml They are after the DDL (So yes the create w/ proper Key's and constraints) – xQbert Jan 11 '17 at 23:00
  • This sort of clarification question can only be answered by the person who set the assignment. There is no explicit request to show the sql code required to create the table. But there probably wouldn't be any harm in including that statement in your answer. Depending on the flavour of sql you're using, it is possible to answer the question with "standalone" statements the alter an _assumed_ table. – Disillusioned Jan 12 '17 at 00:02
  • I'm voting to close this question as off-topic because unanswerable by SO community. Need to clarify with whoever set the exercise. – Disillusioned Jan 12 '17 at 00:04

1 Answers1

0

Based on the context, I would assume it means to write a "CREATE TABLE" statement that includes table name, column names, their corresponding data types, as well as the constraint mentioned, that could be used to store data that would be used to hydrate the class. So for example, the table definition must be able to store a row that has columns such as (202, "Rubik's Cube", "moderate") that represent the puzzle_number, description, and class respectively.

You can enforce the constraint mentioned by using a foreign key to a second table that stores the puzzle classifications, or you can use a check constraint when defining the table to make sure it holds one of the 3 values allowed without having to use a second table.

Simple Create Table reference: http://www.w3schools.com/sql/sql_check.asp

Simple Check constraint reference: http://www.w3schools.com/sql/sql_check.asp

jmscotty
  • 1
  • 1
  • Sorry to say this but the question was very vague. Your answer doesn't really talk about SQL "definition". – Vasif Jan 12 '17 at 00:26