MySQL is an open-source relational database management system (RDBMS). MySQL Workbench is a tool that allows database maintainers to interact with the data in a MySQL database.
The important panes in the instance view are the Navigator, the Query, and the Output. Note where each of these is located:
Most of the work in the Workbench will take place in the Query pane, which allows developers to execute SQL queries.
The connection currently exists, but there is no database! Follow the steps below to create a new MySQL database.
CREATE DATABASE IF NOT EXISTS db;
db
database appears!Now the database exists, but it does not have any tables. Create a table so that the data in the database is organized and meaningful.
USE db;
USE db;
text and click the lightning bolt to execute the statement
CREATE TABLE IF NOT EXISTS movies (
title TEXT,
year INTEGER,
genre TEXT,
director TEXT
);
movies
with title
, year
, genre
, and director
as columnsmovies
table appears!The table exists, but it currently contains no data! Follow the steps below to add some data to the table.
INSERT INTO movies
VALUES ("Going Overboard", 1989, "Comedy", "Valerie Breiman");
SELECT * FROM movies
to check and make sure the movie was successfully added to the tableSELECT *
query and re-execute it to make sure both movies appear!In addition to tracking all of the other Movie properties, this table should store the runtime of the movies in minutes.
ALTER TABLE movies
ADD runtime INTEGER;
runtime
column appears!Now that a new column exists, it is possible to update the existing rows with the more information.
SET SQL_SAFE_UPDATES = 0;
UPDATE movies
SET runtime = 97
WHERE title = "Going Overboard";
UPDATE
statement to set the runtime of “Going Overboard” to 97
SELECT * FROM movies
again to verify that the “Going Overboard” row has the proper runtimeRather than updating the row for “Sandy Wexler,” it is possible to simply delete it.
DELETE FROM movies
WHERE title = "Sandy Wexler";
DELETE
statement to remove the rowSELECT * FROM movies
again to verify that the “Sandy Wexler” row no longer appears