Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Creating The Table - Creating The Table

Creating The Table

Posted on December 21, 2024December 21, 2024 By Rishabh saini No Comments on Creating The Table

Creating the Table

In this tutorial, we will cover the process of creating a new table named Employee in the PythonDB database. Additionally, we’ll learn how to modify the table schema when updates are required. This practical guide demonstrates SQL commands alongside Python code, ensuring seamless integration for developers working with MySQL.

Download New Real Time Projects :-Click here

Creating the Employee Table

The Employee table will initially consist of four columns:

    1. name: Stores the name of the employee (VARCHAR).
    2. id: Unique identifier for each employee (INT, primary key).
    3. salary: Stores the salary of the employee (FLOAT).
    4. Dept_Id: Represents the department ID of the employee (INT).

            We use the SQL CREATE TABLE statement to define the table structure. Here’s the query:

            CREATE TABLE Employee (  
                name VARCHAR(20) NOT NULL,  
                id INT PRIMARY KEY,  
                salary FLOAT NOT NULL,  
                Dept_Id INT NOT NULL  
            );  
            

            Let’s implement this using Python:

            Example: Creating the Employee Table

            import mysql.connector  
            
            # Create the connection object  
            myconn = mysql.connector.connect(  
                host="localhost",  
                user="root",  
                passwd="google",  
                database="PythonDB"  
            )  
            
            # Create the cursor object  
            cur = myconn.cursor()  
            
            try:  
                # Creating the Employee table with four columns  
                cur.execute("""  
                    CREATE TABLE Employee (  
                        name VARCHAR(20) NOT NULL,  
                        id INT PRIMARY KEY,  
                        salary FLOAT NOT NULL,  
                        Dept_Id INT NOT NULL  
                    )  
                """)  
                print("Table Employee created successfully.")  
            except Exception as e:  
                print("Error:", e)  
                myconn.rollback()  
            finally:  
                myconn.close()  
            

            Verifying the Table Creation

            Once the code executes successfully, the Employee table will be created in the PythonDB database. You can verify this by running the following SQL query in your MySQL client:

            SHOW TABLES;  
            

            Modifying the Employee Table

            Sometimes, you may need to update the schema of an existing table. For example, we might need to add a new column named branch_name to the Employee table.

            The SQL ALTER TABLE statement is used to modify table structures. Here’s the query to add the branch_name column:

            ALTER TABLE Employee ADD branch_name VARCHAR(20) NOT NULL;  
            

            Example: Adding a New Column

            Here’s how to implement this schema update using Python:

            import mysql.connector  
            
            # Create the connection object  
            myconn = mysql.connector.connect(  
                host="localhost",  
                user="root",  
                passwd="google",  
                database="PythonDB"  
            )  
            
            # Create the cursor object  
            cur = myconn.cursor()  
            
            try:  
                # Adding a new column branch_name to the Employee table  
                cur.execute("ALTER TABLE Employee ADD branch_name VARCHAR(20) NOT NULL")  
                print("Column branch_name added successfully.")  
            except Exception as e:  
                print("Error:", e)  
                myconn.rollback()  
            finally:  
                myconn.close()  
            

            Summary

            In this guide, we:

              1. Created the Employee table in the PythonDB database with four columns: name, id, salary, and Dept_Id.
                1. Verified the successful creation of the table.
                2. Used the ALTER TABLE statement to add a new column branch_name to the table.

                    PHP PROJECT:- CLICK HERE


                    insert into table sql
                    create table in sql with primary key
                    how to create a table in sql
                    create table and insert data sql
                    create table student details in sql
                    how to create a table in excel with multiple columns
                    create table as select sql server
                    create student table in sql and insert values
                    creating the table oracle
                    creating the table in sql
                    creating the table in dbms
                    creating the table in sql server

                    Post Views: 739
                    Python Tags:create table, creating, creating a table in access, creating a table within excel!, creating table of contents in microsoft word, creating table of contents in ms word, creating table of contents in word, dining room table, dining table, dining table diy, diy dining table, diy table, epoxy table, formatting tables, how to build a dining table, how to build a table, how to create a table, kitchen table, pivot table, river table, table, tables

                    Post navigation

                    Previous Post: PHP Contact Form with PHPMailer
                    Next Post: Student Record and Information System in Java

                    More Related Articles

                    Tkinter LabelFrame Tkinter LabelFrame Widget Python
                    Database Operations: UPDATE and DELETE in MySQL Using Python - Database Operations Database Operations: UPDATE and DELETE in MySQL Using Python Python
                    Web Scraping Using Python - Web Scraping Using Python Web Scraping Using Python Python

                    Leave a Reply Cancel reply

                    Your email address will not be published. Required fields are marked *

                    You may also like

                    1. Python Decorators: A Comprehensive Guide
                    2. How to Calculate Distance between Two Points using GEOPY
                    3. Rock, Paper, Scissors Game
                    4. Database Operations: UPDATE and DELETE in MySQL Using Python
                    5. How to Install Django: Step-by-Step Guide
                    6. Python Tkinter Canvas: A Guide to Structured Graphics in Python

                    Most Viewed Posts

                    1. Top Large Language Models in 2025
                    2. Online Shopping System using PHP, MySQL with Free Source Code
                    3. login form in php and mysql , Step-by-Step with Free Source Code
                    4. Flipkart Clone using PHP And MYSQL Free Source Code
                    5. News Portal Project in PHP and MySql Free Source Code
                    6. User Login & Registration System Using PHP and MySQL Free Code
                    7. Top 10 Final Year Project Ideas in Python
                    8. Online Bike Rental Management System Using PHP and MySQL
                    9. E learning Website in php with Free source code
                    10. E-Commerce Website Project in Java Servlets (JSP)
                    • AI
                    • ASP.NET
                    • Blockchain
                    • ChatCPT
                    • code Snippets
                    • Collage Projects
                    • Data Science Project
                    • Data Science Tutorial
                    • DBMS Tutorial
                    • Deep Learning Tutorial
                    • Final Year Projects
                    • Free Projects
                    • How to
                    • html
                    • Interview Question
                    • Java Notes
                    • Java Project
                    • Java Script Notes
                    • JAVASCRIPT
                    • Javascript Project
                    • JSP JAVA(J2EE)
                    • Machine Learning Project
                    • Machine Learning Tutorial
                    • MySQL Tutorial
                    • Node.js Tutorial
                    • PHP Project
                    • Portfolio
                    • Python
                    • Python Interview Question
                    • Python Projects
                    • PythonFreeProject
                    • React Free Project
                    • React Projects
                    • Spring boot
                    • SQL Tutorial
                    • TOP 10
                    • Uncategorized
                    • Online Examination System in PHP with Source Code
                    • AI Chatbot for College and Hospital
                    • Job Portal Web Application in PHP MySQL
                    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
                    • Online Job Portal System in JSP Servlet MySQL

                    Most Viewed Posts

                    • Top Large Language Models in 2025 (8,615)
                    • Online Shopping System using PHP, MySQL with Free Source Code (5,218)
                    • login form in php and mysql , Step-by-Step with Free Source Code (4,872)

                    Copyright © 2026 UpdateGadh.

                    Powered by PressBook Green WordPress theme