Create Your First SQL Project: Adding a Customer Table to an E-Commerce Database

Create Your First SQL Project: Adding a Customer Table to an E-Commerce Database

Table of contents

No heading

No headings in the article.

Resources:

Guide:

  1. Connect to the database using MySQL Workbench and select the appropriate schema.

  2. Create a new table named "customers" with the following columns:

  • customer_id (primary key, auto-increment)

  • first_name (varchar(255))

  • last_name (varchar(255))

  • email (varchar(255))

  • password (varchar(255))

  • address (varchar(255))

  • city (varchar(255))

  • state (varchar(255))

  • zip_code (varchar(255))

Use the following SQL statement:

CREATE TABLE customers ( customer_id INT AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(255), last_name VARCHAR(255), email VARCHAR(255), password VARCHAR(255), address VARCHAR(255), city VARCHAR(255), state VARCHAR(255), zip_code VARCHAR(255) );

  1. Insert sample data into the customers table using the INSERT statement. For example:

INSERT INTO customers (first_name, last_name, email, password, address, city, state, zip_code) VALUES ('John', 'Doe', '', 'password123', '123 Main St', 'New York', 'NY', '10001');

  1. Test the table by querying it using the SELECT statement. For example:

SELECT * FROM customers;

  1. Once the table is working correctly, commit the changes to the database.

Congratulations, you have successfully added a customer table to the e-commerce database!