📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 284question

DATA MANIPULATION THROUGH SQL · Part 10

Chapter 4: 6 · COMPUTER SCIENCE

'B', 'M', . , ' - - ') ( , 'Priyanka', 'A', 'F', . , ' - - ') ( , 'TARUN', 'D', 'M', . , ' - - ') 12th Computer Chapter - - Data input by User .

In this example we are going to accept data using Python input() command during runtime and then going to write in the Table called "Person" Example . - # code for executing query using input data import sqlite3 # creates a database in RAM con =sqlite3.connect("Academy.db") cur =con.cursor() cur.execute("DROP Table person") cur.execute("create table person (name, age, id)") print("Enter students names:") who =[input() for i in range( )] print("Enter their ages respectively:") age =[int(input()) for i in range( )] print("Enter their ids respectively:") =[int(input())for i in range( )] n =len(who) for i in range(n): # This is the q-mark style: cur.execute("insert into person values (?, ?, ?)", (who[i], age[i], [i])) cur.execute("select * from person") # Fetches all entries from table print("Displaying All the Records From Person Table") print (*cur.fetchall(), sep='\n' ) 12th Computer Chapter - - Data Manipulation Through SQL OUTPUT Enter students names: RAM KEERTHANA KRISHNA HARISH GIRISH Enter their ages respectively: Enter their ids respectively: Displaying All the Records From Person Table ('RAM', , ) ('KEERTHANA', , ) ('KRISHNA', , ) ('HARISH', , ) ('GIRISH', , ) You can even add records to the already existing table like “Student” Using the above coding with appropriate modification in the Field Name. To do so you should comment the create table statement Execute (sql[, parameters]) :- Executes a single SQL statement. The SQL statement may be parametrized (i.

e. Use placeholders instead of SQL literals). The sqlite3 module supports two kinds of placeholders: question marks? (“qmark style”) and named placeholders :name (“named style”).

Note 12th Computer Chapter - - Using Multiple Table for Querying . Python allows to query more than one table by joining them. In the following example a new table called “Appointment” which contain the details of students Rollno, Duty, Age is created. The tables “student” and “Appointment” are joined

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →