In this post, I will walk through some basic MySQL commands used in database testing.
Connect to a database
To create a table, you must use the CREATE TABLE command and specify the table name and fields. The following command creates the department:
CREATE TABLE department (
dept_name char(20) NOT NULL,
dept_number numeric(1) NOT NULL,
mgrSSN numeric(9) NOT NULL,
mgrStartDate date NOT NULL,
PRIMARY KEY (dept_number),
We can check the structure of a table with the help of DESCRIBE command. The command lets you view a table
mysql> DESCRIBE department;
mysql> DESC dept;
Note that we have written SQL keywords in capital letters. It is a coding standard of writing an SQL query. This is to enhance the readability of the SQL query to others. SQL is NOT case sensitive.
Since you’ve created a table, you can begin inserting data to it. The
INSERT command is shown below to add a record to the table. The values must be listed in exactly the same order as the fields. Each value is separated by a comma, and all VARCHAR & CHAR data type values must be enclosed in single quotation marks.
INSERT INTO department VALUES
SELECT command is used, if you want to view the data in a table.The command to view all the data in
a table is shown below:
SELECT * FROM department;