DEV Community

Daniel Karanja
Daniel Karanja

Posted on

Basic Introduction to SQL

MySQL is a widely recognized, freely available, and open-source database application that is highly regarded for its exceptional performance, user-friendly interface, and robust data security measures. As a result, it has become a preferred choice for many seeking a reliable database solution.
This comprehensive guide will walk you through the process of creating tables in MySQL, as well as inserting data into them. Additionally, you will learn about various techniques for querying the data stored within these tables.

*Step 1:Creating a database *

1. Create a database using the CREATE statement:
  CREATE DATABASE movies;
2. To verify that the database was created use the SHOW statement;
  SHOW DATABASES;
3. Select the database to make changes to it by using the USE statement:
 USE movies;
Enter fullscreen mode Exit fullscreen mode

Step 2

Step 3: Create a Table
We’ll create a table containing information about movies:
CREATE TABLE movies(title VARCHAR(50) NOT NULL,genre VARCHAR(30) NOT NULL,director VARCHAR(60) NOT NULL,release_year INT NOT NULL,PRIMARY KEY(title));

- Verify that the table is created using the DESCRIBE command:
DESCRIBE movies;

Insert movie information in column order – title, genre, director, and release year. Use the INSERT command:
INSERT INTO movies VALUE ("Fast and furious X", "action", "Justin Lin", 2023);

- Use the SELECT command to display the table:
   SELECT * FROM movies;
Enter fullscreen mode Exit fullscreen mode

Step 3: Create a view
Views are SQL queries that display data based on defined parameters.

  1. Create a view named minimum_release_year to display movie titles whose release year is after 1990. Use the CREATE VIEW command and define query parameters:

CREATE VIEW minimum_release_year AS SELECT title FROM movies WHERE release_year > 2002;

  1. Display the view using the SELECT command: SELECT * FROM minimum_release_year; The output displays movies released after the year 2002.

Top comments (0)