How to Create Relationship Tables in MySQL: A Step-by-Step Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024
  • 🚀 HeidiSQL Tutorial: Creating Relationship Tables in MySQL 🚀
    Welcome back, everyone! In today's tutorial, I'll guide you through the process of creating tables in databases using HeidiSQL. Follow along step by step to master this essential skill.
    ⚙️ Creating a New Database:
    Launch HeidiSQL and navigate to the "Databases" tab.
    Right-click, choose "New," then select "Database."
    Enter the desired name (e.g., "company_db") and configure optional settings.
    Click "OK" to create the new database.
    ⭐️ Creating the 'Department' Table:
    Select the "company_db" database.
    Right-click, choose "Create new," and enter "department" as the table name.
    Navigate to the "Columns" tab and add columns like "department_id" and "department_name."
    Set column types and properties, then click "Save" to create the 'department' table.
    ⭐️ Creating the 'Personnel' Table with Relationships:
    Again, select the "company_db" database.
    Create a new table named "personnel" with columns like "personnel_id," "firstname," "lastname," and "department_id."
    Switch to the "Foreign Keys" tab and establish a relationship with the 'department' table.
    Click "Save" to create the 'personnel' table.
    📊 Adding Data to the Tables:
    Use the "Query" tab to open a new window in HeidiSQL.
    Copy and paste the provided Insert queries from the video description.
    Click "Run" to execute the queries and populate your tables with data.
    🚀 Congratulations! You've successfully created and linked tables using HeidiSQL. Stay tuned for more tutorials, and don't forget to like, share, and subscribe for future updates! If you have any questions, feel free to leave a comment below. Happy coding! 🔍✨
    -- Inserting sample data into the department table
    INSERT INTO department (department_name) VALUES
    ('Sales'),
    ('Marketing'),
    ('Human Resources'),
    ('Finance'),
    ('Information Technology'),
    ('Operations'),
    ('Customer Service'),
    ('Research and Development'),
    ('Legal'),
    ('Administration'),
    ('Public Relations'),
    ('Quality Assurance'),
    ('Purchasing'),
    ('Product Management'),
    ('Supply Chain'),
    ('Training and Development'),
    ('Facilities Management'),
    ('Business Development'),
    ('Compliance'),
    ('Risk Management');
    -- Inserting sample data into the personnel table
    INSERT INTO personnel (first_name, last_name, department_id) VALUES
    ('John', 'Doe', ROUND(RAND() * 20) + 1),
    ('Alice', 'Smith', ROUND(RAND() * 20) + 1),
    ('Michael', 'Johnson', ROUND(RAND() * 20) + 1),
    ('Emily', 'Williams', ROUND(RAND() * 20) + 1),
    ('Christopher', 'Brown', ROUND(RAND() * 20) + 1),
    ('Jessica', 'Jones', ROUND(RAND() * 20) + 1),
    ('Matthew', 'Garcia', ROUND(RAND() * 20) + 1),
    ('Samantha', 'Martinez', ROUND(RAND() * 20) + 1),
    ('Daniel', 'Anderson', ROUND(RAND() * 20) + 1),
    ('Olivia', 'Wilson', ROUND(RAND() * 20) + 1),
    ('David', 'Taylor', ROUND(RAND() * 20) + 1),
    ('Sophia', 'Thomas', ROUND(RAND() * 20) + 1),
    ('Andrew', 'Hernandez', ROUND(RAND() * 20) + 1),
    ('Emma', 'Lopez', ROUND(RAND() * 20) + 1),
    ('James', 'Gonzalez', ROUND(RAND() * 20) + 1),
    ('Madison', 'Young', ROUND(RAND() * 20) + 1),
    ('Logan', 'Wilson', ROUND(RAND() * 20) + 1),
    ('Grace', 'Lee', ROUND(RAND() * 20) + 1),
    ('Ethan', 'Clark', ROUND(RAND() * 20) + 1),
    ('Ava', 'Lewis', ROUND(RAND() * 20) + 1),
    ('Benjamin', 'Walker', ROUND(RAND() * 20) + 1),
    ('Chloe', 'Hall', ROUND(RAND() * 20) + 1),
    ('William', 'Allen', ROUND(RAND() * 20) + 1),
    ('Natalie', 'Moore', ROUND(RAND() * 20) + 1),
    ('Liam', 'Perez', ROUND(RAND() * 20) + 1),
    ('Mia', 'Hill', ROUND(RAND() * 20) + 1),
    ('Henry', 'Scott', ROUND(RAND() * 20) + 1),
    ('Ella', 'Green', ROUND(RAND() * 20) + 1),
    ('Jacob', 'Adams', ROUND(RAND() * 20) + 1),
    ('Avery', 'Baker', ROUND(RAND() * 20) + 1),
    ('Lily', 'Rivera', ROUND(RAND() * 20) + 1);
    #HeidiSQL #MySQLTutorial #DatabaseManagement #CodingTutorial #TechLearn #SQL #DataManagement

ความคิดเห็น •