Menu

Creating And Using A Database

In this section, we are going to explain the things that you should know about creating and using a database. Learn about creating and using a database is very important for programmers

This improves your knowledge in the following areas. 

  1. Creating and Selecting a Database
  2. Creating a Table
  3. Loading Data into a Table
  4. Retrieving Information from a Table

Creating and selecting a database

       CREATE DATABASE database_name;

To make use of this database, you have to use the use command.

       USE database_name;

There is an alternate way to select the database. Just specify the name and connection parameters that you need to provide.

      mysql -h host -u user -p database_name
      Enter password: ********

Creating a Table

      CREATE TABLE table_name (
          col1 datatype,
          col2 datatype,
          col3 datatype,
          ....
       );

Loading Data into a Table

After creating the table there are two ways to load the data into the table. They are load and insert.

Loading the data using LOAD command,

       LOAD DATA LOCAL INFILE '/path_to_the_file_folder/file_name.txt' INTO TABLE table_name;

Retrieving Information from a Table

       SELECT col1,col2....coln
       FROM table_name1, table_name2....
       WHERE conditions
       [OFFSET O][LIMIT L]