Short Answer Type Question
Short Answer Type Question
1. Observe the following table and answer the parts (i) and (ii) accordingly
3. What is the importance of the primary key in a table? Explin with a suitable example.
Ans: The primary key is an attribute/set of attribute that identifies a tuple/row/record
uniquely.
Example:
Roll_no in STUDENT table
OR
Pan_Number in INCOMETAX table
4. Write the python script to read the whole data from the table emp and display all the
records.
Ans:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="root",database="s
chool")
print (mydb)
mycursor=mydb.cursor()
numrow=mycursor.execute("select * from student")
print(mycursor.fetchall())
mydb.close()
5. Write the python function to accept the name as parameter and find out whether record
present in the table or not
Ans:
import mysql.connector
def check_name(name):
mydb=mysql.connector.connect(host="localhost",user="root",passwd="root",
database="school")
print(mydb)
cur=mydb.cursor()
cur.execute("select * from student")
s=cur.fetchall()
for k in s:
if((k[1]==name)):
print("Record Found",k)
break
6. What is MySQL?
Ans:
MySQL is an open source DBMS which is built, supported and distributed by MySQL
AB (now acquired by Oracle)
7. What are the technical features of MySQL?
Ans : MySQL database software is a client or server system which includes
Multithreaded SQL server supporting various client programs and libraries Different
backend Wide range of application programming interfaces and Administrative tools
8. Why MySQL is used?
Ans : MySQL database server is reliable, fast and very easy to use. This software can be
downloaded as freeware and can be downloaded from the internet.
9. What are tables and Fields?
Ans: A table is a set of data that are organized in a model with Columns and Rows.
Columns can be categorized as vertical, and Rows are horizontal. A table has specified
number of column called fields but can have any number of rows which is called record.
Example:.
Table: Employee.
Field: Emp ID, Emp Name, Date of Birth.
Data: 201456, David, 11/15/1960.
10. What is a primary key?
Ans: A primary key is a combination of fields which uniquely specify a row. This is a
special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary
key values cannot be NULL.
11. What is a unique key?
Ans: A Unique key constraint uniquely identified each record in the database. This
provides uniqueness for the column or set of columns.
A Primary key constraint has automatic unique constraint defined on it. But not, in the
case of Unique Key.
There can be many unique constraint defined per table, but only one Primary key
constraint defined per table.
12. What is a foreign key?
Ans: A foreign key is one table which can be related to the primary key of another table.
Relationship needs to be created between two tables by referencing foreign key with the
primary key of another table.
13. What is a join?
Ans: This is a keyword used to query data from more tables based on the relationship
between the fields of the tables. Keys play a major role when JOINs are used.
14. What is CLAUSE?
Ans : SQL clause is defined to limit the result set by providing condition to the query.
This usually filters some rows from the whole set of records.
Example – Query that has WHERE condition
Query that has HAVING condition.
15. What is an ALIAS command?
ALIAS name can be given to a table or column. This alias name can be referred in
WHERE clause to identify the table or column.
Example-.
Select st.StudentID, Ex.Result from student as st, Exam as Ex where st.studentID = Ex.
StudentID