Skip to content
Worked Examples · Example 10

Q.Write SQL statements to

(i) create a database named 'SchoolDB',
(ii) start using it, and
(iii) create a table 'Student' with fields RollNo (whole number, primary key), Name (text up to 50 characters), Class (text up to 10 characters) and Marks (whole number).
ChseodishaTextbookSubjectiveImportance★★★★★est
67% · 10/15 Questions
✓ Free question

These are three DDL jobs done one after another.

(i) Create the database with CREATE DATABASE:

CREATE DATABASE SchoolDB;

(ii) Select it with USE, so that the following commands act on SchoolDB:

USE SchoolDB;

(iii) Create the table with CREATE TABLE, listing each field and its data type. A whole number uses INT; text of up to n characters uses VARCHAR(n); the identifying field is marked PRIMARY KEY.

  • RollNo — whole number and primary key → RollNo INT PRIMARY KEY
  • Name — text up to 50 characters → Name VARCHAR(50)
  • Class — text up to 10 characters → Class VARCHAR(10)
  • Marks — whole number → Marks INT
CREATE TABLE Student (
    RollNo INT PRIMARY KEY,
    Name VARCHAR(50),
    Class VARCHAR(10),
    Marks INT
);

After these statements, SchoolDB contains an empty Student table ready for records. Note that keywords are capitalised by convention and every statement ends with a semicolon.

✓Final answer

CREATE DATABASE SchoolDB;
USE SchoolDB;
CREATE TABLE Student (
    RollNo INT PRIMARY KEY,
    Name VARCHAR(50),
    Class VARCHAR(10),
    Marks INT
);

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.