KwickAcademy Databases and SQL · 6 min · free
SQL Data Definition: CREATE DATABASE, CREATE TABLE, ALTER and DROP
CREATE DATABASE makes a database and USE selects it. CREATE TABLE sets columns, types and constraints; ALTER changes them; DROP removes them. DROP has no undo, so back up first.
Follows the syllabus of: CBSE Class 10 Information Technology (402), CBSE Class 12 Computer Science (083), CBSE Class 11 Informatics Practices (065), CBSE Class 11 Information Technology (802)
On screen in this lesson
Remember about USE
| Creating a database does not select it |
| Without USE, MySQL says: No database selected |
| Run USE again every time you log in |
Constraints: rules on columns
| PRIMARY KEY: unique and never empty |
| NOT NULL: a value must always be given |
| UNIQUE: no two rows can have the same value |
| DEFAULT: value used when none is given |
Why DROP is dangerous
| There is no undo: DDL commands save at once |
| DROP DATABASE removes every table inside it |
| Always take a backup before you DROP |
| DELETE removes rows; DROP removes the whole table |
Quick recap
| CREATE DATABASE makes it; USE selects it |
| CREATE TABLE: name, data type, constraint per column |
| PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT set the rules |
| ALTER TABLE: ADD, MODIFY, DROP COLUMN, ADD PRIMARY KEY |
| DROP TABLE and DROP DATABASE cannot be undone |
Quick answers
Why does MySQL say 'No database selected'?
You created the database but did not run USE.
What is the difference between DELETE and DROP?
DELETE removes rows; DROP removes the whole table.
KwickClips from this lesson
Short clips, one idea each. Good for revision the night before.
Why the error 'No database selected'?39 sec
How do you stop two students sharing a roll number?43 sec
Do you have to recreate a table to add a column?40 sec
Can a DROP be undone?37 secThe full lesson, in text
Hello students, welcome to Kwickprep. One short command can delete a whole school's data in less than a second, with no undo. Which command is it? Today we will create a database and a table with rules, change the table with alter, and learn why drop is so dangerous.
A database is like a cupboard that holds many tables. Create database school makes a new, empty database called school. Show databases lists every database, so you can check that school is there. Use school tells My S Q L that the next commands are for this database. Show tables lists its tables, and right now there are none.
Students often forget one thing about use. Creating a database does not automatically select it. If you skip use and create a table, My S Q L gives the error, no database selected. And every time you log in again, you must run use once more.
A constraint is a rule that a column must follow, and the database checks it on every row. Primary key means the value is unique and never empty. Not null means the value can never be left empty, and null means no value. Unique means no two rows can have the same value, but an empty value is allowed. Default gives a ready value when the user does not supply one.
Here is the student table with all four constraints. Each column has a name, a data type, and then its constraint. Roll is an int and the primary key. Name is var char of thirty and not null, so every student must have a name. Email is unique, so two students cannot share one. City has a default of Surat. Commas separate the columns, and the brackets close with a semicolon.
Let us test the rules with one row. We insert roll one and the name Riya, but we give no city. Pause and predict. What city will Riya get? The output shows Surat, because the default filled it in. If we now insert roll one again for Aman, My S Q L refuses with a duplicate entry error for the primary key.
Alter table changes the structure of a table that already exists, without losing its rows. Add phone char of ten adds a new column at the end, and old rows get null in it. Modify changes a column's data type or size, so name can now hold fifty characters. Be careful, modify replaces the whole column definition. If we leave out not null here, the name column quietly loses that rule.
Drop column phone removes the column and every value stored in it. Next, suppose we made a marks table and forgot the primary key. Alter table marks, add primary key, roll, adds it later. This works only if roll has no repeated values and no empty values. Otherwise, My S Q L refuses to add the key.
How do we check that alter worked? Desc student, short for describe, shows every column and its rules. The output here is shortened to fit the screen. Roll is the primary key, and name is now var char of fifty and cannot be null. Email is unique, city keeps its default of Surat, and the phone column is gone.
Now the most powerful commands. Drop table marks deletes the marks table completely, its structure and all its rows. Drop database school deletes the entire database, with every table inside it. Both run instantly, and My S Q L does not ask, are you sure?
Here is why drop is so dangerous. In My S Q L, D D L commands are saved at once, so there is no undo. Drop database wipes every table inside it, like a whole year of marks and fees. So always take a backup first, and read the command twice before pressing enter. Also, do not confuse the two: delete removes rows but keeps the table, while drop removes the table itself.
Let us revise what we learned today. Create database makes a database, and use selects it. Create table lists each column with its name, data type and constraint. Primary key, not null, unique and default are the four rules we used. Alter table can add, modify or drop a column, and add a primary key later. Drop table and drop database cannot be undone, so back up first.
Courses that teach this
| Course | Unit |
|---|---|
| CBSE Class 10 Information Technology (402) | Digital Documentation (Advanced) using LibreOffice Writer |
| CBSE Class 12 Computer Science (083) | Database Management |
| CBSE Class 11 Informatics Practices (065) | Database concepts and the Structured Query Language |
| CBSE Class 11 Information Technology (802) | Part B, Unit 4: RDBMS |
| CBSE Class 12 Information Technology (802) | Database Concepts - RDBMS Tool |
| GSEB Std 11 Computer Studies | Working with Tables |
Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.
Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

