Articles on Trending Technologies

Technical articles with clear explanations and examples

How to add comment to column in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 631 Views

A comment is a readable explanation provided about something. The comments in the code are provided to explain the purpose of the code staement used. This enables the outside person to understand the need and use of that particular code.The comments are ignored by the compilers and are not executed. These are just for the explanatory purpose and are of great importance.We can add comments to columns in a sql table. These comments will explain the function or tell something about the column. If some other person is viewing and working on that table, he can get idea about the ...

Read More

How to get the id after INSERT into MySQL database using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 9K+ Views

The data is inserted into the table in Mysql using the INSERT statement. While inserting the data into the table, either the data must be provided in the same order as the column definition in the database or the column names must be provided along with the data while using INSERT statement.To get and print the ID of the last inserted row, lastrowid is used. This is a special keyword which is used to get the ID of the last inserted row. There are certain prerequisites to be taken care of before using this method.The ID column must be the ...

Read More

Explain the use of COUNT() AND SUM() in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 3K+ Views

These are the functions used to perform the arithmetic operations on the column values in a table.The COUNT() function is used to return the number of rows which satisfy a certain condition.The SUM() function is used to return the sum of numerical values in a column in the table.The NULL values are ignored.SyntaxCOUNT()SELECT COUNT(column_name) FROM table_name WHERE conditionSUM()SELECT SUM(column_name) FROM table_nameSteps invloved to use count() and sum() functions on a table using MySQL in pythonimport MySQL connectorestablish connection with the connector using connect()create the cursor object using cursor() methodcreate a query using the appropriate mysql statementsexecute the SQL query using ...

Read More

How to copy a table in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 3K+ Views

We can create copy of an existing table in mysql using Python. The entire table will be copied including the columns, the column definitions and all the rows of the table.SyntaxCREATE TABLE table_name SELECT * FROM existing_tabletable_name is the name of the new table to be created. existing_table is the name of the table which is to be copied.Steps to copy a table using MySQL in pythonimport MySQL connectorestablish connection with the connector using connect()create the cursor object using cursor() methodcreate a query using the appropriate mysql statementsexecute the SQL query using execute() methodclose the connectionSuppose, we have a table ...

Read More

What is the rollback() method in Python MySQL?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 4K+ Views

The rollback() method is one among the various methods in Python which is used to make the database transactions.Here, we will discuss about the rollback() method.The rollback() method is used to revert the last change or commit made to the database. If a condition arises such that the user is not satisfied with the changes made to the database, or if the transaction fails, then the rollback() method is operated to bring the database to its original state which was before committing the changes. This is a very important method as it helps in maintaing the integrity of the database ...

Read More

What is Python commit() method in MySQL?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 22K+ Views

The commit() method is one among the various methods in Python which is used to make the database transactions.Here, we will discuss about the commit() method. The commit() method is used to confirm the changes made by the user to the database. Whenever any change is made to the database using update or any other statements, it is necessary to commit the changes. If we donot use the commit() method after making any changes to the database, the database will not not be updated and changes will not be reflected.Syntaxdb.commit()db refers to the database connection object.Given below is an example ...

Read More

Explain the use of MIN() and MAX() using MySQL in Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 1K+ Views

The MIN() and MAX() functions are used to perform arithmetic operations on the columns of the table.As the name suggests, the MIN() function is used to select and return the samllest value from the selected column.The MAX() function, on the other hand, selects and returns the highest value from the selected column.SyntaxMIN()SELECT MIN(column_name) FROM table_nameMAX()SELECT MAX(column_name) FROM table_nameSteps invloved in finding minimum and maximum value from a column in table using MySQL in pythonimport MySQL connectorestablish connection with the connector using connect()create the cursor object using cursor() methodcreate a query using the appropriate mysql statementsexecute the SQL query using execute() ...

Read More

How can you perform inner join on two tables using MySQL in Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 3K+ Views

We can join two tables in SQL based on a common column between them or based on some specified condition. There are different types of JOIN available to join two SQL tables.Here, we will discuss about the inner join on two tables.JOIN and INNER JOIN both work the same way. The INNER JOIN matches each row in one table with every row in other table and allows to combine the rows from both the tables which either have somecommon column or which satisfy some condition which is specified.When applying join among two tables, we need to specify the condition based ...

Read More

How can you avoid getting an error if you are deleting a table which does not exist using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 700 Views

There might be a scenario where you might be deleting a table which actually does not exist in your database. It is possible that while executing the command to delete a table from the database, we may give wrong name of the table which doesnot exist in our database. The another possibility is that you are deleting a table which was already deleted by someone else who has access to the database. In this scenario you will get an error while executing the command since the table you wish to delete is not present.This error can be avoided by checking ...

Read More

How can you retrieve a particular number of records from a table starting from some specified row number in Python MySQL?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 1K+ Views

Most frequently, we do not require to select all the rows from the table. We may at times need to retrieve a particular number of records from a table, starting from some specific index. Suppose, we have a table of 10 records. We need to select 5 rows from the table starting from 3rd row.This is done using the LIMIT and OFFSET clause along with the SELECT statement. The LIMIT is used to specify the number of rows that you want to retrieve. The OFFSET is used to specify the starting position from where the rows are to be fetched. ...

Read More
Showing 30841–30850 of 61,248 articles
Advertisements