12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications மின்னணு தரவு பரிமாற்றம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிக பாதுகாப்பு அமைப்புகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின்னணு செலுத்தல் முறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications மின் - வணிகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications திறந்த மூல கருத்துருக்கள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு வடமிடல் Sample Question Papers Study Material - QB365 Set A

Published on: 13/09/2022
QB365 provides a detailed and simple solution for every Possible Creative Questions in Class 12 Computer Science Subject - Data Manipulation Through SQL , English Medium. It will help Students to get more practice questions, Students can Practice these question papers in addition to score best marks.
Download Tamil Nadu 12th Standard Computer Science question papers, model tests, one-mark questions, important questions, and public exam papers in PDF format. Free study materials and answer keys for TN State Board students.
Questions + Answers key
Take MCQ Computer Science Test

1.
Python 3 Program To Demonstrate Staircase Pattern.
2.
Multiplication Table Program in Python.
3.
Write a program to store and retrieve the given data in SQLlite3.
4.
With an example program, how will you input the data at run tirne?
5.
How will you delete a record from the table? Explain briefly with an example.
6.
How will you update a record, Give an example.
7.
Explain in detail about aggregate functions with an example.
8.
Explain the SQL operators with clauses in detail.
9.
Explain in detail about various clauses in SQL.
10.
Explain in detail about fetching records from the table.
11.
Explain briefly about SELECT Query.
1.
#function definition def pattern(n):
#for loop for rows for i in range(1, n +1):
#conditional operator
k = i + 1 if(i % 2! = 0) else i
#for loop for printing spaces for g in range (k, n):
if g>=k:
print(end = " ")
#according to value of k carry
#out further operation for j in range (0,k):
if j == k-1: print(" * ")
else:
print(" * ", end = " ")
#Driver code n = 10
pattern(n)
Output:
| * | * | ||||||||
| * | * | ||||||||
| * | * | * | * | ||||||
| * | * | * | * | ||||||
| * | * | * | * | * | * | ||||
| * | * | * | * | * | * | ||||
| * | * | * | * | * | * | * | * | ||
| * | * | * | * | * | * | * | * | ||
| * | * | * | * | * | * | * | * | * | * |
| * | * | * | * | * | * | * | * | * | * |
2.
#A multiplication table for digit def multiplication_table():
"'multiplication_table() ->none
prints a multiplication table for base 10 that is 10 x 10."'
#prints the top row string
= ' ' topRow string = ' '
for column in range(1,11): topRowstring + = '\t' + str(column)
print(topRowstring)
string + = topRowstring + '\n'
#print each subsequent row for row in range (1,11):
rowstring = str(row) for column in range(1,11):
rowstring + = '\t' + str(row*column) print(rowString)
string + = rowString + '\n' return string
multiplication_table()
3.
Python allows to query more than one table by joining them. In this example a new table called 'Appointments" which contains the details of students Roll no, Duty, Age is created. The tables "student" and "Appointments" are joined and displayed the result with the column headings.
Example:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor()
cursor.execute""""DROP TABLE Appointment;""""
sql_command = """CREATE TABLE Appointment (rollno int primary key, duty varchar (10), age int)"""
sql_command = """ INSERT INTO Appointment (Rollno, Duty, age) VALUES ("2", "security", "16");"""
cursor.execute (sql_command)
connection.commit()
cursor.execute("SELECT student. Rollno, student.sname, Appointment.
Duty, Appointment. Age from student, Appointment where student.roll no = Appointment.roll no")
#print the details
co = [i[0] for i in cursor.description]
print(co)
#field informations can be read.
result = cursor.fetchall()
for r in result:
print(r)
Output:
['Roll no', 'Sname', 'Duty', 'age']
(1, 'Akshay', 'Perfect', 17)
(2, 'Aravind', 'Secratery', 16)
4.
In this example we are going to accept data using Python input ()command during run time 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 5 students names:")
who = [input() for i in range(5)]
print("Enter their respectively:")
age = [int(input for i in range(5)]
print("Enter their respectively:")
p_id = [int(input( ))for i in range(5)]
n = len(who)
for i in range(n):
#This is the q-mark style:
cur.execute ("insert into person values (?,?,?)", (who[i], age[i], p_id[i]))
#Add this is the named style:
cur.execute ("select*from person")
#fetches all entries from table
print("Displaying All the records from Person Table")
print(* cur.fetchall(), sep = '\n')
Output:
Enter 5 students names:
RAM
KEERTHANA
KRISHNA
HARISH
GIRISH
Enter their ages respectively:
28
12
21
18
16
Enter their ids respectively:
1
2
3
4
5
Displaying All the Records from Person Table
('RAM' 28, 1)
('KEERTHANA' 12,2)
('KRISHNA' 21,3)
('HARISHI' 18,4)
('GIRISH' 16,5)
We 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 we should comment the create table statement.
5.
Similar to sql command to delete a record, Python also allows deleting a record. In this example delete the content of Rollno 2 from "student table".
Example:
#code for delete operation
import sqlite3
#database name to be passed as parameter
conn = sqlite3.connect ("Academy.db")
#delete the student record
conn.Execute ("DELETE FROM student where RollNo = '2'")
conn.commit()
print("Total number of rows deleted:", conn.total_changes)
cursor = conn.Execute("SELECT* FROM student")
for row in cursor:
print(row)
conn.Close()
Output:
Total number of rows deleted: 1
(1, 'Akshay', 'B', 'M', 87.8, '2001-12-12')
(3, 'Basker', 'C', 'M', 75.2, '1999-05-17')
(4, 'SAJINI', 'A', 'F', 95.6, '2002-11-01')
(5, 'VARUN', 'B', 'M', 80.6, '2002-03-14')
(6, 'Priyanka' 'A', 'F', 98.6, '2002-01-01')
(7, 'TARUN'. 'D', 'M', 62.3, '1999-02-01')
6.
We can even update a record (tuple) in a table through Python script. Example to change the name "Priya" to "Priyanka" in a record "in student table".
Example:
#code for update operation
import sqlite3
#database name to be passed as parameter
conn = sqlite3. connect ("Academy.db")
#update the student record
conn.Execute ("UPDATE student SET Sname = 'Priyanka' where RollNo = "6")
conn.commit()
print("Total number of rows updated:", conn.total_changes)
cursor = conn.Execute("SELECT* FROM student")
for row in cursor:
print(row)
conn.Close()
Output:
Total number of rows updated: 1
(1, 'Akshay', 'B', 'M',87.8, '2001-12-12')
(2, 'Aravind', 'A', 'M', 92.5, '2001-08-17')
(3, 'BASKER', 'C', 'M', 75.2, '1998-05-17')
(4, 'SAJINI', 'A', 'F', 95.6, '2002-11-01')
(5, 'VARUN', 'B', 'M', 80.6, '2001-03-14')
(6,'Priyanka', 'A, 'F', 98.6, '2002-01 -01')
(7,'TARUN', 'D', 'M', 62.3, '1999-02-01')
7.
1. Count function:
The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. COUNTY() returns 0 if there were no matching rows.
Example:
We are going to count the number of records.
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor ( )
cursor. execute ("SELECT COUNT (*) FROM student")
result = cursor.fetchall ( )
print (*result, sep = "\n")
Output:
[(7,)]
2. AVG function:
The following SQL statement in the Python program finds the average mark of all students.
Example:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor ( )
cursor. execute ("SELECT AVG (AVERAGE) FROM student")
result = cursor. fetchall ( )
print (*result, sep = "\n")
Output:
[(84.65714285714286,)]
3. SUM function:
The following SQL statement in the Python program finds the sum of all averages in the Average field of the "student table".
Example:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor ( )
cursor.execute ("SELECT SUM (AVERAGE) FROM student")
result = cursor.fetchall ( )
print (result)
Output:
[(592.6)]
4. Max and Min function:
(i) The MAX( ) function returns the largest value of the selected column.
(ii) The MIN( ) function returns the smallest value of the selected column.
(iii) The following example shows the highest and least average student's name.
Example:
import sqlite3
connection = sqlite3.connect ("Organization.db")
cursor = connection.cursor( )
cursor.execute ("SELECT Sname, MAX(AVERAGE) FROM student")
result = cursor.fetchall ( )
print(result)
print("Displaying the name of the Least Average")
cursor.execute ("SELECT Sname, MIN(AVERAGE) FROM student")
result cursor.fetchall()
print(result)
Output:
Displaying the name of the Highest Average [('PRIYA', 98.6)]
Displaying the name of the LeastAverage [('TARUN', 62.3)]
8.
1. Example for where with NOT operator:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor ( )
cursor.execute ("SELECT *FROM student where Grade< > 'A' and Grade < > 'B'")
result = cursor.fetchall ( )
print (*result, sep = "\n")
Output:
(3, 'BASKER', 'C', 'M', 75.2, '1999-05-17')
(5,, 'THARUN', 'D', 'M', 62.3, '1999-02-01")
2. Exarnple for wherewith AND operator:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor ( )
cursor.execute ("SELECT Roll no, Sname, Average FROM student WHERE (average > =80 AND average < =90")
result = cursor.fetchall ( )
print (*result, sep = "\n")
Output:
(1, 'Akshay', 87.8)
(5, 'VARUN', 80.6)
3. Example for where with OR operator:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection. cursor ( )
cursor.execute ("SELECT Roll no, Sname FROM student WHERE (average < 60 AND average >70)")
result = cursor.fetchall ( )
print (*result, sep = "\n")
Output:
(1, 'Akshay')
(2, 'Aravind' )
(3, 'BASKAR')
(4, 'SAJINI')
(5, 'VARUN')
(6, 'PRIYA')
9.
1. Distinct clause:
The distinct clause is helpful when there is a need of avoiding the duplicate values present in any specific columns/table. When we use distinct keywords only the unique values are fetched. in this example, we are going to display the different grades scored by students from the "student table".
Example:
import Sqlite3
connection = sqlite3.connect (''Academy.db'')
cursor = connection.cursor ( )
cursor.execute ("SELECT DISTINCT(Grade) FROM student")
result = cursor.fetchall ( )
print (result)
Output:
[('B',), ('A',), ('C',), ('D',)]
2. WHERE clause:
The WHERE clause is used to extract only those records that fulfill a specified condition. In this example we are going to display the different grades scored by male students from "student table".
import Sqlite3
connection = sqlite3.connect (''Academy.db'')
cursor = connection.cursor ( )
cursor.execute ("SELECT DISTINCT(Grade) FROM student where gender = 'M'")
result = cursor. fetchall ( )
print (*result, sep = "\n",)
Output:
('B',)
('A',)
('C',)
('D',)
3. GROUP BY clause:
The SELECT statement can be used along with GROUP BY clause. The GROUP BY clause groups records into summary rows. It returns one records for each group. It is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns. In this example count the number of male and females from the student table and display the result.
Example:
import Sqlite3
connection = sqlite3.connect (''Academy.db'')
cursor = connection.cursor ( )
cursor.execute ("SELECT gender, count(gender) FROM student GROUP BY gender")
result = cursor. fetchall ( )
print (*result, sep = "\n",)
Output:
('F',2)
('M',5)
4. ORDER BY clause:
The ORDER BY clause can be used along with the SELECT statement to sort the data of specific fields in an ordered way. It is used to sort the result set in ascending or descending order. Example to display name and Roll no of the students alphabetical order:
Example:
import sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection. cursor ( )
cursor. execute ("SELECT Roll no, Sname FROM student order by sname")
result = cursor. fetchall ( )
print (*result, sep = "\n")
Output:
(1, 'Akshay')
(2, 'Aravind')
(3, 'BASKAR')
(6, 'PRIYA')
(4, 'SAJINI')
(7, 'TARUN')
(8, 'VARUN')
5. Having clause:
HAVING clause is used to filter data based on the group functions. This is similar to WHERE condition but can be used, only with group functions. Group functions cannot be used in WHERE Clause but can be used in HAVING clause.
Example:
import sqlite3
connection = sqlite3.connect("Academy.db")
cursor = connection.cursor()
cursor.execute("SELECT GENDER,COUNT(GENDER) FROM Student GROUP BY GENDER HAVING COUNT( GENDER > 3")
result = cursor.fetchall( )
co = i[0] for i in cursor. description]
print(co)
print(result)
Output:
['gender', 'count(GENDER)']
[('M', 5)]
10.
1. fetch all:
The fetchall() method is used to fetch all rows from the database table.
Example:
import Sqlite3
connection = sqlite3.connect ("Academy.db")
cursor = connection.cursor()
cursor.execute("SELECT *FROM student")
print("fetchall:")
result = cursor.fetchall()
for r in result:
print(r)
Output:
2. fetch all:
(1, 'Akshay', 'B', 'M', 87.8, '2001-12-12')
(2, 'Aravind', 'A', 'M', 92.5,'2001-08-17')
(3, 'Baskar', 'C', 'M', 95.2, '1998-05-17')
(4, 'SAJINI', 'A', 'F', 95.6, '2002-11-01')
(5, 'VARUN', 'B', 'M', 80.6, '2001-03-14')
Fetchone:
The fetch one() method returns the next row of a query result set or none in case there is no row left.
Example:
import sqlite3
connection = sqlite3.connect (''Academy.db'')
cursor = connection.cursor( )
cursor.execute ("SELECT *FROM student")
print("\n fetchone:")
res = cursor.fetchone( )
print(res)
Output:
3. fetchone:
(1, 'Akshay', 'B', 'M', 87.8, '2001-1212')
Using while loop and fetchone() Method we can display all the records from a table.
Example:
import sqlite3
connection = sqlite3.connect (''Academy.db'')
cursor = connection.cursor ( )
cursor.execr,rte ("SELECT *FROM student")
print("fetching all records one by one:")
result = cursor.fetchone( )
while result is not None:
print(result)
result = cursor.fetchone()
Output:
fetching all records one by one:
(1, 'Akshay', 'B', 'M', 87.8, '2001-1212')
(2, 'Aravind', 'A', 'M', 92.5, '2000-08-17')
(3, 'Basker', 'C', 'M', 95.2, '1999-05-17')
(4, 'SAJINI', 'A', 'F', 95.6, '2002-11-01')
(5, 'VARUN', 'B', 'M', 80.6, '2002-03-14')
4. Fetchmany:
Displaying specified number of records is done by using fetchmany(). This method returns the next number of rows(n) of the result set.
Example:
import sqlite3
connection = sqlite3.connect (''Academy.db'')
cursor = connection.cursor ( )
cursor.execr,rte ("SELECT *FROM student")
print("fetching first 3 records:")
result = cursor.fetchmany(3)
print(result)
Output:
fetehing first 3 records:
(1, 'Akshay', 'B', 'M', 87.8, '2001-1212')
(2, 'Aravind', 'A', 'M', 92.5, '2000-08-17')
(3, 'Basker', 'C', 'M', 95.2, '1999-05-17')
11.
1. "Select" is the most commonly used statement in SQL. The SELECT statement in SQL is used to retrieve or fetch data from a table in a database. The syntax for using this statement is "select * from table_name" and all the table data can be fetched in an object in the form of list of lists.
2. If we run this program, saved as "sql_Academy_query.py", we would get the result, depending on the actual data:
3. It should be noted that the database file that will be created will be in the same folder as that of the Python file. tf we wish to change the path of the file, change the path while opening the file.
Example:
#Save the files as "sql_Academy_query.py"
#cursor object
crsr = connection.cursor
#executive the command to fetchall the data from the table students
crsr. execute ("SELECT *FROM student")
#Store all the fetched data in the ans variable
ans = crsr.fetchall ()
#loop to print all the data
for i in ans:
print(i)
12th Standard Syllabus & Materials
12th Standard
TN 12th Computer Applications களப்பெயர் முறைமை (DNS) Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications வலையமைப்பு எடுத்துக்காட்டுகள் மற்றும் நெறிமுறைகள் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications கணினி வலையமைப்பு ஓர் அறிமுகம் Sample Question Papers Study Material - QB365 Set A
NEW12th Standard
TN 12th Computer Applications PHP-உடன் MySQL-ஐ இணைத்தல் Sample Question Papers Study Material - QB365 Set A
Tamilnadu Stateboard 12th Standard Subjects

Maths

Chemistry

Physics

Biology

Computer Science

Business Maths and Statistics

Economics

Commerce

Accountancy

History

Computer Applications

Biology

Computer Technology

Computer Applications

Computer Science

Business Maths and Statistics

Commerce

Economics

Maths

Chemistry

Physics

Computer Technology

History

Accountancy

Tamil

English

French
Tamilnadu Stateboard Standards