Computer Science
Write a Python code to insert a new record as per given table Student (No, Name, Age, Department, Fee, Sex) using MySQL connectivity.
Python
Python MySQL
3 Likes
Answer
import mysql.connector
mydb = mysql.connector.connect(host = "localhost",
user = "root",
passwd = "kboat123",
database = "kboat_cbse_12")
mycursor = mydb.cursor()
mycursor.execute("INSERT INTO STUDENT VALUES(5, 'ANANYA', 23, 'COMPUTER', 450, 'F')")
mydb.commit()
print("Records added")
mydb.close()Output
Records added
Answered By
1 Like
Related Questions
Write a function reverseFile() in Python to read lines from text file 'TESTFILE.TXT' and display the file content in reverse order so that the last line is displayed first and the first line is displayed at the end.
Consider the following table STUDENT.
NO NAME AGE DEPARTMENT FEE SEX 1 PANKAJ 24 COMPUTER 120 M 2 SHALINI 21 HISTORY 200 F 3 SANJAY 22 HINDI 300 M 4 SUDHA 25 HISTORY 400 F Write a Python code to search a record as per given NO (number) using MySQL connectivity and print the data.
A binary file "salary.Dat" has structure [employee id, employee name, salary]. Write a function countrec() in Python that would read contents of the file "salary.Dat" and display the details of those employees whose salary is above 20000.
A departmental store "ABC" is considering maintaining their inventory using SQL to store data and maintain basic transactions. As a database manager, Mehak has to create two tables as Customer & Transaction:
Table: CUSTOMER
CNo CNAME ADDRESS 101 Richa Jain Delhi 102 Surbhi Sinha Chennai 103 Lisa Thomas Bengaluru 104 Imran Ali Delhi 105 Roshan Singh Chennai Table: TRANSACTION
Dept CNO AMOUNT TYPE DOT T001 101 1500 Credit 2017-11-23 T002 103 2000 Debit 2017-05-12 T003 102 3000 Credit 2017-06-10 1004 103 12000 Credit 2017-09-12 T005 101 1000 Debit 2017-09-05 (i) Identify the attribute best suited to be declared as a Primary key in customer table.
(ii) Help Mehak to display details of all transactions of TYPE Credit from Table TRANSACTION.
(iii) Mehak wants to display all CNO, CNAME and DOT (date of transaction) of those CUSTOMERS from tables CUSTOMER and TRANSACTION who have done transactions more than or equal to 2000 for the Balance Sheet.
(iv) Mehak wants to display the last date of transaction (DOT) from the table TRANSACTION for the customer having CNO as 103. Which command will she use?