You are on page 1of 5

Practice Questions for Viva

Sub: Computer Science


MYSQL
1. Full Form of SQl : Structured Query Language
2. Types of command:
a) DDl - Data Definition Language, used to define and change structure of table e.g create
table, alter table and drop table
b) DML - data Manipulation language, used to insert,update delete data in table e.g insert
into, delete, update, select command
c) TCL - Transaction Control Language e.g commit, rollback
3. MySql is Relational Database Management system in which data is stored in form of tables.
Table is intersection of rows and columns
e.g Student

Roll No Name Marks


1 Rahul 45
2 Sagar 67
3 Sameer 78
4 Pooja 89
5 Deepak 90
Basic Terms used in MySQL
Relation: Table Name: i.e Student
Attributes: Name of Columns i.e Rollno, Name and Marks
Degree: No. of Columns i.e 3
Tuple: Single row in a table
Cardinality: No. of rows in a table i.e 5 in above table
4. Which Command is used to create table in MySql?
Ans: create table command is used
e.g create table student ( roll int, name char(10), float marks);

5. Which command is used to add row/record in a table

Ans: insert into command is used

e.g insert into student values(1,”Rahul’,45);

6. Which command is used to add a new column Address into the table

Ans: Alter table command is used to add a new column in a table

Alter table student

Add Address char(20);

7. Which command to used to change data/values in a table suppose we have to increase the
marks of Rahul by 5.

Ans: Update command is used to modify data/values in table

Update student

Set marks =marks+5

Where Name =’Rahul’;

8. Difference between update and alter table command

Ans: Update is DML command ,used to modify data/values in table

Alter table is DDL command , used to add ,modify, drop column in a table
9. Which command is used to delete the records from table

Delete command is used to delete the records from table

e.g we we have to delete recprd of Rahul.

Delete from student where name=’rahul’;

10. Which Command is used to delete/remove table permanently.

Drop Table command is used to remove table permanently

Drop Table Student;

11. Difference between Delete and Drop table command

Delete command is used to delete the records from table

Drop Table command is used to remove table permanently

12. Which command is used to display all record from table

Select statement is used

Select * from student;

13 Which clause is used to arrange data in ascending/decending order

Order by clause is used

e.g select * from student order by marks;

14 Name aggregate functions in MYSQL

Sum(), min(),max(),count(),avg()

15. Difference between count() and count(*)

Count(*) it will count all rows including null values

Count() it will count all rows not including null values

16. what is use of like operator?

Like operator is used for pattern matching

_(underscore sign) replace single character

% sign replaces number of characters

Select * frome student where name like ‘R%’;

17. Which clause is used to search for NULL values in any column?

Ans: IS NULL

18. What is use of group by clause

Ans: it is used for gropuing of rows and for condition with group by clause having will be used in
place of where.

Select grade, count(*) from student group by grade having count(*)>1;

19. Define stack

Ans: Stack is a data structure with technique last in first out(LIFO)

Insertion(Push) and deletion(POP) from TOP.


Python Sql Connectivity Questions
1. Which module/connector will be used for python sql connectivity
Ans: import mysql.connector
2. Which function is used for connection with database in MySql
Ans: connect () is used
3. How many parameters connect function will take?
Connect function will take 4 parameters

Mysql.connector,connect(host=’localhost’,userid=’1234’,password=’1234’,database=’school’)

4. Which function is used to check whether connection is established or not?

Ans: is_connected()

Mysql.connector.is_connected()

5. Define cursor?

Ans: Cursor Is A Control Structure Used To retrieve row by row processing of records in
resultset

6. Which Function Is Used To Run/Execute Sql Statement In Python?

Ans: Execute()

7. What is resultset?

Ans: it refers to logical set of records that are fetched from database by executing a query and
made available to application program

8. Which function is used to retrieve data from resultsert/database

Ans: fetchone() : it will return one record from resultset as a tuple. If there is no record
then it will return none.

Fetchmany(n): it will return n records and if there is no record then it will return none.

Fetchall() it will return all record from resultset in form of tuple

9. Which object of cursor is used to count no. Of rows retrieved from cursor?
Ans: row count

Cursor.rowcount

10. To save changes made in database permanently , you need to run connection._______
method.

Ans: commit()

11. Explain the given statement:


cur.execute("CREATE TABLE student (Roll INT(5), name CHAR(10), class
VARCHAR(20), marks float);")

Cursor is executing the sql statement using execute function which will create table in mysql
named student with columns rollno, name , marks and clas
12. Explain the given statement:
Cur.execute( "insert into student values ({},'{}',{},{})".format(rno, name, clas,
marks”;)
Cursor is executing the sql statement using execute function which will insert the record by
passing parameterized query (run time)using {} and format()
DataFile Handling:

Text File Binary File CSVfile


Meaning Stores information in Stores information in CSV(coma separated
ASCII characters form of 0 1nd 1 binary value) file it is Same as
form text file it can also be
opened in Ms-Excel
format
Module _____ Pickle module Csv module
used
File Modes r- reading rb- reading in binary r- reading
used w-writing wb-writing in binary w-writing
a-append ab-append in binary a-append
r+,a+,w+ for both r+,a+,w+ for both r+,a+,w+ for both
rading and writing rading and writing rading and writing
Reader() and ______ ______ Reader() is required for
writer () reading. It loads data
required from csv file.
Writer() is required for
writing
Function for Read()- returns in form Pickle.Load(a)- takes Using travesrsing of list
reading of string one parameter, a is For i in a:
Readline()- in form of name of file object Print(i)
string where a is reader
Readlines()- in form of object
list
Function for Write(a)- takes string Pickle.dump(b,a)- takes Writerow(list) – for
writing as parameter two parameters b is writing single row
Writelines(a)- takes list what to write and a is
as a parameter where to write i.e file Writerows(list)for
object writing multiple rows

2. Difference between ‘a’ and ‘w’ mode

a- append . if file is there ,then add at the end of file

w- add in file if file is there then it will delete previous data and add new i.e overwrite the
existing file

3. what is extension of python program file?

Ans: .py

4. Give Example of following:


a) List x=[10,20,30] Mutable x[1]=100 valid
b) Tuple y=(10,20,30) immutable y[1]=100 invalid
c) String z=”cbse” immutable z[1]= ‘P’ invalid
d) Dictionary m={1:”one,2:”two”,3:”three”}

List, string and tuple are example of sequence as they supports indexing

Dictionary is example of mapping indexing is not there

5. Keywords- system defined words e.g if , for,else,def


6. Identifiers - user defined words e.g marks,myfile
7. Function – set of statements def keyword is used to define function
8. Traversing- means displaying the elements one by one
9. Example of Traversing:
X=[10,20,30]
for i in X:
print(i)

You might also like