I'm sure you've heard the news... SQL is essential! Let's dive in and create an employees table step-by-step. First, we use the CREATE TABLE statement. Think of it as setting up a new folder where all your employee data will live. Next, we define our columns- employee_id INT PRIMARY KEY - This is your unique identifier for each employee. first_name and last_name - Both are VARCHAR(50) NOT NULL, meaning up to 50 characters, and you can't leave them empty. email - This is VARCHAR(100) NOT NULL UNIQUE. It must be unique and can't be blank. hire_date - A DATE field to store when the employee was hired. job_title - VARCHAR(50). This one’s optional. salary - DECIMAL(10, 2), to handle salaries with up to two decimal places. Finally, department_id - INT, which can connect to another table, like departments. And that's it! You’ve just created an employees table. Practice makes perfect, so keep coding! Happy querying!
コメント