3.5 Inserting records into tables
Inserting
records into tables: -
- To insert the records into tables, we use the “insert into” query.
- Import mysql.connector.
- Connect to the MySQL database using connect( ) method.
- Create a cursor( ) object, then pass the SQL insert query command as a string to the execute( ) method.
Syntax: -
- To insert only single record into table, we use
- To insert multiple records into table, we use
- The SQL command to insert the records or data into table in database with python code is:
output: -
- To view the records of table, we use command.