+91 81900 98289

MySQL Create Table

This MySQL Create Table lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

CREATE TABLE names the columns and the type of each column. A primary key identifies one row.

The example stores an empty table of learner rows.

Example 1: Start here

A typical statement starts CREATE TABLE learner (id INT, name VARCHAR(80), city VARCHAR(40)).

tables = {"learner": []} # a dictionary; each key has one value print(list(tables))

Example 2: Filter the rows

MySQL Create Table is easier to see as a list of records. The filter keeps every row whose seats value is at least 10.

rows = [{"topic": "MySQL Create Table", "seats": 12}, {"topic": "SQL", "seats": 12}] # a list; the values stay in this order print([row["topic"] for row in rows if row["seats"] >= 10]) # keep the items that pass the test

Example 3: Update one field

An update changes one field and leaves the rest of the record alone. On a database you would run an UPDATE or an update_one for the same change.

row = {"topic": "MySQL Create Table", "seats": 12} # a dictionary; each key has one value row["seats"] = row["seats"] + 1 # change this one field print(row)

Example 4: Count the matches

Counting matches is the idea behind COUNT(*). Here the number 12 appears twice.

rows = [12, 4, 12] # a list; the values stay in this order print(sum(1 for value in rows if value == 12)) # keep the items that pass the test
A typical statement starts CREATE TABLE learner (id INT, name VARCHAR(80), city VARCHAR(40)).
Call Now 81900 98289