My First Database
Overview
- Prerequisites
- Create Database Connection
- Create Database within Database Connection
- Create Table within Database
- Create Record within Table
Prerequisites
Create MySQL Connection
Install MySQL Driver
Create Database
- Execute the command below to create a new database named
databaseName
CREATE DATABASE IF NOT EXISTS databaseName;
Create Table
- Execute the command below to create a new table within the database named
tableName.- The table will have a column representative of its
primary key, namedidof typeintegerwhichauto incrementsupon record insertion. - The table will have a column representative named
nameof typetextwhichauto incrementsupon record insertion.
- The table will have a column representative of its
CREATE TABLE IF NOT EXISTS databaseName.tableName(
id INT AUTO_INCREMENT PRIMARY KEY,
name TEXT NOT NULL,
name_abbreviation VARCHAR(3));
Insert Records
INSERT INTO databaseName.tableName(id, name, name_abbreviation) VALUES
(1, "Leon", "LEO");
INSERT INTO databaseName.tableName(id, name, name_abbreviation) VALUES
(2, "Christopher", "CRS");
INSERT INTO databaseName.tableName(id, name, name_abbreviation) VALUES
(3, "Hunter", "HNT");
Select All Records
SELECT * FROM databaseName.tableName
Select All Records Where
SELECT * FROM databaseName.tableName WHERE id > 1





