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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp