SQL Database Creation and Querying: Hands-On Exercises

Starting a New Database

  1. Creating the ‘escola’ database

    CREATE DATABASE escola;

  2. Opening the database for use

    USE escola;

Creating Tables

Creating the ‘aluno’ (student) table

CREATE TABLE aluno (RA INT(4), nome CHAR(30), nascimento DATE, sex CHAR(1), cidade CHAR(30), year INT(1), codcurso INT(3));

Creating the ‘course’ table

CREATE TABLE course (code INT(3), nome CHAR(30), Duracao INT(1));

Inserting Data into Tables

Inserting data into the ‘aluno’ table

Insert yourself and four friends into the ‘aluno’ table:

Read More