MySQL + SQL · Lesson 35
CREATE DATABASE and CREATE TABLE
Create a Database
CREATE DATABASE school;
USE school;
SHOW DATABASES;
Create a Table
CREATE TABLE students (
roll_no INT PRIMARY KEY,
name VARCHAR(60) NOT NULL,
class VARCHAR(10),
marks INT DEFAULT 0
);A table "students" is created with 4 columns and a primary key.
See the Structure
DESC students; -- shows columns and types
SHOW TABLES; -- lists all tables
Summary
- CREATE DATABASE makes a database; USE selects it.
- CREATE TABLE defines columns, types and constraints.
- DESC shows table structure.