SQL Data Entry and Queries

From the study guide

Course Outline

  1. Creating the Database and Tables
  2. Adding Table Constraints
  3. Modifying Table Structure
  4. Inserting and Validating Data
  5. Selecting and Sorting Data

Key Dates

  1. 15 September 2026Yassine registered for swimming and karate.
  2. 20 September 2026Salma registered for fitness.
  3. 1 October 2026Ines registered for fitness and swimming.

1. Creating the Database and Tables

★ Must-know

  • Create a table with CREATE TABLE, listing each column and its type; declare a single-column primary key by adding PRIMARY KEY to that column.

📌 A composite primary key is declared once at the end of the table, as PRIMARY KEY (cin, codeAct); writing PRIMARY KEY separately for each column is an error.

  • The adherents table contains:
    • cin CHAR(8) as the primary key
    • nom VARCHAR(30)
    • prenom VARCHAR(30)
    • email VARCHAR(40)
    • age INT
    • adresse VARCHAR(50)

Further detail

  • Create and select a database with CREATE DATABASE name; followed by USE name;.

  • The activites table contains:

    • codeAct CHAR(4) as the primary key
    • libelle VARCHAR(30)
    • tarif DECIMAL(6,3)
    • places INT

2. Adding Table Constraints

Read the full study guide →

Practice quiz preview

1. An `age` check uses `CHECK (age BETWEEN 12 AND 70)`. Which age is accepted by the constraint?

2. Which definition correctly specifies the `adherents` table’s columns and primary key?

3. A table has a column named adresse, which must be renamed ville and given the type VARCHAR(30); which ALTER TABLE operation does this?

Take the quiz (17 questions) →

Flashcard preview

How do you declare a single-column primary key when creating a table?

Add `PRIMARY KEY` to that column’s definition.

Which column is the primary key of the `adherents` table?

`cin CHAR(8)`.

Which fields and types make up the `adherents` table besides its primary key?

`nom VARCHAR(30)`, `prenom VARCHAR(30)`, `email VARCHAR(40)`, `age INT`, and `adresse VARCHAR(50)`.

How is the composite primary key `(cin, codeAct)` declared?

Once at the end of the table as `PRIMARY KEY (cin, codeAct)`.

Why is declaring `PRIMARY KEY` separately for each composite-key column an error?

A composite primary key must be declared once at the end of the table.

How does `ALTER TABLE` make a column mandatory using `MODIFY`?

Use `MODIFY column TYPE NOT NULL`, rewriting the column’s type.

See all 39 flashcards →

Frequently asked questions

What does the SQL Data Entry and Queries study guide cover?

It covers the core concepts of SQL Data Entry and Queries, organized by topic with the key definitions, explanations and takeaways, so it's easier to learn and remember.

Read the full study guide →

How many questions are in the SQL Data Entry and Queries quiz?

The practice quiz has 17 multiple-choice questions, each with an explanation. Use it to check what you know and find your gaps.

Take the quiz (17 questions) →

How do I study SQL Data Entry and Queries with flashcards?

There are 39 flashcards on SQL Data Entry and Queries, with a question on the front and the answer on the back. Try to recall each answer before you flip, and let spaced repetition bring back the ones you miss.

See all 39 flashcards →

Related classes

Turn your own class notes into a study guide

Upload a PDF or paste your notes. Revizly writes a study guide, a practice quiz and flashcards in about a minute.