- - , Aravind, A, M, . , - - , BASKAR, C, M, . , - - , TARUN, D, M, . , - - , VARUN, B, M, .
, - - , PRIYA, A, F, . , - - , SAJINI, A, F, . , - - 12th Computer Chapter - - Example . - Opening the file (“sqlexcel.csv”) through MS-Excel and view the result (Program is same similar to EXAMPLE .
- script) import sqlite3 import csv # database name to be passed as parameter conn = sqlite3.connect("Academy.db") print(“Content of the table before sorting and writing in CSV file”) cursor = conn.execute("SELECT * FROM Student") for row in cursor: print (row) # CREATING CSV FILE d=open('c:\pyprg\sqlexcel.csv','w', newline= ' ') c=csv.writer(d) cursor = conn.cursor() cursor.execute("SELECT * FROM student ORDER BY GENDER DESC,SNAME") #WRITING THE COLUMN HEADING co = [i[ ] for i in cursor.description] c.writerow(co) data=cursor.fetchall() for item in data: c.writerow(item) d.close() print(”sqlexcel.csv File is created open by visiting c:\pyprg\sqlexcel.csv”) conn.close() By default while writing in a csv file each record ends with \n (newline) to eliminate this newline replace () is used during the reading of csv file. Note 12th Computer Chapter - - Data Manipulation Through SQL OUTPUT Content of the table before sorting and writing in CSV file ( , 'Akshay', 'B', 'M', . , ' - - ') ( , 'Aravind', 'A', 'M', . , ' - - ') ( , 'BASKAR', 'C', 'M', .
, ' - - ') ( , 'SAJINI', 'A', 'F', . , ' - - ') ( , 'VARUN', 'B', 'M', . , ' - - ') ( , 'Priyanka', 'A', 'F', . , ' - - ') ( , 'TARUN', 'D', 'M', .
, ' - - ') sqlexcel.csv File is created open by visiting c:\pyprg\sqlexcel.csv OUTPUT THROUGH EXCEL A B C D E F Rollno Sname Grade gender Average Akshay B M . - - Aravind A M . - - BASKAR C M . - - TARUN D M .
- - VARUN B M . - - PRIYA A F . - - SAJINI A F . - - Table List .
To show (display) the list of tables created in a database the following program (Example . – ) can be used. Example . –