levo

SQL, Big Data and Distributed Systems

Creating tables: CREATE TABLE, data types and keys

  • 3 things to know
  • Component 2

Overview

Writing the statement that builds a table — column names and their data types, the PRIMARY KEY clause and the NOT NULL constraint.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

A school needs a table called Pupil with PupilID as a whole number and Surname as twenty characters. Write the SQL.

Key term

What is the purpose of the PRIMARY KEY clause in a CREATE TABLE statement?

Key term

What does the NOT NULL constraint do?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    A school needs a table called Pupil with PupilID as a whole number and Surname as twenty characters. Write the SQL.

    Model answer

    CREATE TABLE Pupil (PupilID Int, Surname Char(20)). The brackets enclose the column list and each column name is followed by its data type.

  2. 2

    What is the purpose of the PRIMARY KEY clause in a CREATE TABLE statement?

    Model answer

    The PRIMARY KEY clause names the column whose value uniquely identifies each row. The database system then rejects any duplicate or empty value in that column.

  3. 3

    Write SQL to create a table Pupil in which PupilID is a whole-number primary key and Surname is twenty characters that may not be left empty.

    Model answer

    CREATE TABLE Pupil (PupilID Int PRIMARY KEY, Surname Char(20) NOT NULL). The second constraint forces a surname to be supplied in every row.

  4. 4

    What does the NOT NULL constraint do?

    Model answer

    The NOT NULL constraint prevents a column being left empty. The database system refuses any row that has no value in that column.

  5. 5

    Which SQL data type stores a whole number such as a year group?

    Model answer

    Int is the data type for a whole number. Int stores a year group of 11 with no decimal part.

  6. 6

    What does Char(n) mean in a table definition?

    Model answer

    Char(n) declares a fixed-length text column of n characters. Char(30) reserves thirty character positions in every row.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Data Structures: Arrays, Records and Hash Tables
Stacks, Queues, Linked Lists and Trees
Boolean Logic and Simplification
Algorithms, Pseudo-Code and Programming Constructs

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

KDW to HAT.
decryptsencryptscompresses

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe two are not the same.
BOpen source refers to the availability of the code.
CMuch open source software is free of charge.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Backup means the copy of the data.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in SQL, Big Data and Distributed Systems, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.