Posts

Showing posts from August, 2020

SQL INSERT statement

Image
                                                    The INSERT statement - Part I Example :          use employees; SELECT     * FROM     employees LIMIT 10; #insert data insert into employees(     emp_no,     birth_date,     first_name,     last_name,     gender,     hire_date ) values(     999901,     '1999-10-10',     'John',     'wick',     'M',     '2020-08-31'     );     SELECT     * FROM     employees WHERE     emp_no = 999901;                                                   The INSERT statement - Part II      We must put he values in the exact order we have listed the column name. The INSERT statement - exercise 1 Select ten records from the “titles” table to get a better idea about its content. Then, in the same table, insert information about employee number 999903. State that he/she is a “Senior Engineer”, who has started working in this position on October 1 st , 1997. At the end, sort the records from the “titles”

SQL SELECT statement

Image
                                                                             SELECT FROM SELECT - FROM - exercise Select the information from the “dept_no” column of the “departments” table. Select all data from the “departments” table.    SELECT - FROM - solution SELECT     dept_no FROM     departments;   SELECT     * FROM     departments;                                                             WHERE clause     It will allow us to set  a condition upon which we  will specify what part  of the  data we want to retrieve from the DB. WHERE - exercise Select all people from the “employees” table whose first name is “Elvis”. 😊   WHERE - solution SELECT     * FROM     employees WHERE     first_name = 'Elvis';                                                               AND operator  AND : Allow you to logically combine two statements in the condition code block. Allow us to narrow the output

MySQL constraints

Image
                                                                   Constraint                 Constaints define a specific rules, or limits , that we define in our tables               - The roll of constraints is to outline the existing replationships between                          deffirent tables in our database.                   e.g : NOT NULL                 PRIMARY KEY CONSTRAINTS :           PRIMARY KEY constraint - exercise Drop the “customers” table and re-create it using the following code: CREATE TABLE customers                                                               (       customer_id INT,       first_name varchar(255),       last_name varchar(255),       email_address varchar(255),       number_of_complaints int,   primary key (customer_id)   );       Then, create the “items” table   (columns - data types:   item_code – VARCHAR of 255,   item – VARCHAR of 255,   unit_price – NUMERIC of 10 and 2,   company­_id – VARCHAR of 255),   and