Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

SQL New

The document discusses various SQL concepts and questions related to database, tables, queries, and aggregate functions. Some key points: - It provides questions about database and table related concepts like primary keys, cardinality, degrees as well as DDL, DML commands. - Questions related to creating and dropping databases and tables, inserting and deleting records from tables. - Questions about aggregate functions like sum, avg, max, min and writing queries using aggregate functions. - Questions about different clauses in SQL like order by, group by, having, distinct and pattern matching operators. In summary, the document contains SQL questions that test understanding of fundamental database, table concepts and writing basic queries and

Uploaded by

o234035
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

SQL New

The document discusses various SQL concepts and questions related to database, tables, queries, and aggregate functions. Some key points: - It provides questions about database and table related concepts like primary keys, cardinality, degrees as well as DDL, DML commands. - Questions related to creating and dropping databases and tables, inserting and deleting records from tables. - Questions about aggregate functions like sum, avg, max, min and writing queries using aggregate functions. - Questions about different clauses in SQL like order by, group by, having, distinct and pattern matching operators. In summary, the document contains SQL questions that test understanding of fundamental database, table concepts and writing basic queries and

Uploaded by

o234035
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

VELAMMAL VIDHYASHRAM SURAPET – CH-66.

(iii) Insert the following data into the attributes Rollno, Name, Class,
Fees and Qtr in fees table.
Grade 12A5 PRACTICE SHEET 2 Subject: Computer Science (iv) Aman want to remove the table Fees table from the database
School. Which command will he use from the following:
1. As a database administrator, answer any 4 of the following questions: a) DELETE FROM Fees;
Name of the table : SOFTDRINK b) DROP TABLE Fees;
The attributes are as follows: c) DROP DATABASE Fees;
Drinkcode, Calories - Integer d) DELETE Fees FROM Fees;
Price - Decimal (v) Now Aman wants to display the structure of the table Fees, i.e,
Dname - Varchar of size 20 name of the attributes and their respective data types that he has
used in the table. Write the query to display the same.
3.

a) Identify the attributes that can be called Candidate keys.


b) What is the cardinality and degree of the table SOFTDRINK.
c) Include the following data in the above table.
Drinkcode = 107, Dname = “Milkshake” and Calories = 125
d) Give the command to remove all the records from the table.
e) Write a query to create the above table with Drinkcode as the Primary Key.

2. Modern Public School is maintaining fees records of students. The


database administrator Aman decided that-
• Name of the database -School Answer the following questions based on the table LIBRARY:-
• Name of the table – Fees (a) Write the Degree & Cardinality of the relation LIBRARY.
• The attributes of Fees are as follows: (b) Identify the best attribute which may be declared as Primary key.
Rollno - numeric (c) Insert the following record in the above relation:
Name – character of size 20 (10009, ”Motivational Songs”, 15, 70)
Class - character of size 20 (d) Write an SQL query to display the minimum quantity.
Fees – Numeric (e) Database administrator wants to count the no. of CDs which does not have
Qtr – Numeric any Price value. Write the query for the same.
Answer any four from the following questions:
(i) Identify the attribute best suitable to be declared as a primary key
(ii) Write the degree of the table.
VELAMMAL VIDHYASHRAM SURAPET – CH-66. 20.In SQL, what is the use of IS NULL operator? [1]
21.Write any one aggregate function used in SQL. [1]
Grade 12A5 SLIP TEST Subject: Computer Science 22.Which of the following is a DDL command? [1]
a) SELECT b) ALTER c) INSERT d) UPDATE
1. In SQL, name the clause that is used to arrange identical data into groups.[1]
2. Write the aggregate functions used in SQL. [1]
23.In SQL, write the query to display the list of tables stored in a database. [1]
3. In SQL, what is the used of DISTINCT command.? [1]
24.Which of the following types of table constraints will prevent the entry of
duplicate rows?
4. Write any two DML commands? [1] a) check b) Distinct c) Primary Key d) NULL [1]
5. In SQL, write the query to display the databases created. [1] 25.In SQL, name the clause that is used to display the tuples in descending order
6. Write the full form of DML [1] of an attribute [1]
7. By default the ORDER BY clause in SQL lists the results in __________ 26.In SQL, What is the use of check constraint? [1]
order. [1] 27.Which of the following functions is not an aggregate function? [1]
8. Which operator performs pattern matching in SQL? [1] (i) round() (ii) sum( ) (iii) Count (iv) avg( )
9. Avg() is a _____________function in SQL. [1] 28.Which of the following is/are a DML command? [1]
a) math b) text c) aggregate d) numeric a) CREATE b) DROP c) UPDATE d) INSERT
10.Riju wanted to find the subject in which she has scored highest marks. Suggest 29.In SQL, write a query to display all databases on the sql server [1]
a function in SQL to find the highest mark? [1] 30.Which of the following in SQL is used to switch to a database named
11.In SQL, write a query to display all the details from the table ACADEMICS . [1] ‘employee’ [1]
12.What is Primary key? Give example. [1] a) Show employee b) Use employee
13.Write a query to display the Sum, Average, Highest and Lowest salary of the c) Describe employee d) Create employee
employees. [1] 31.A relation has 45 tuples & 5 attributes, what will be the Degree & Cardinality
14.Consider the table with structure as: [1] of that relation? [1]
Student(ID, name, dept name, tot_cred) i. Degree 5, Cardinality 45 ii. Degree 45, Cardinality 5
Which attribute will form the primary key? iii. Degree 50, Cardinality 45 iv. Degree 50, Cardinality 2250
a. Dept b. ID c. Total credits d. Name 32.In SQL, write the query to display the list of tables stored in a database. [1]
15. SQL applies conditions on the groups through ________ clause after groups
have been formed. [1]
a. Where b. Group by c. Having d. With
16.What do you understand by the terms Candidate Key and Cardinality of
relation in the relational database. [1]
17. A(n) ________ in a table represents a logical relationship among a set of
values. [1]
a. Entry b. Key c. Attribute d. Tuple
18.All aggregate functions except ___________ ignore null values in their input
collection. [1]
a) Count (attribute) b) Count (*) c) Avg () d) Sum ()
19.In SQL, name the clause that is used to display the tuples in ascending order of
an attribute. [1]
VELAMMAL VIDHYASHRAM SURAPET – CH-66. 16.___________Command is used to delete table

Grade 12A5 SLIP TEST Subject: Computer Science completely/permanently.


1. _________ statement is used to show all the existing databases 17.Write a query to delete the table “Emp” permanently.
in server. 18.Delete from emp;
2. Which statement is used to show all existing table in database. The above command will delete all the records from table
3. Write statement to open a database named “student”. “emp”. (True/False)
4. Name the command used to create database. 19.Write a query to display all the records from table “Student”
5. Write statement to create database named “book” 20.What do you mean by aggregate function?
6. ___________ command is used to remove database 21.Which keyword is used to arrange records in increasing or
completely. decreasing order?
7. Which command is used to show the structure of the table. 22.Which function returns the total number of records in a table?
desc describe 23.____________ function return the average value of a numeric
8. Is Null value is equivalent to Zero? _________ column.
9. What do you mean by Null in MySQL? 24.Which function returns the sum of numeric column?
10.Which command is used to modify data in table? 25._______ keyword removes duplicates records from the table.
11.Write a query to modify the Contactno to 98789878 whose roll 26.Identify the error in the following statement.
number is 1 in table student. Select * from student where name = null
12.Which command is used to delete data from the table? 27.Which function return the minimum value from column fee of
13.Which command is used to add column in a table? table student?
14.Write a query to add the column DOB of data type date in 28.What is the difference between drop and delete command?
table Student. 29.Differentiate between Alter and Update command.
15.Write a query to add new column “Grade” of data type
varchar(2) in table ‘Student’ with default value “A”.
Table : Student 10.Write a query statement to open the database “Myclass”.

1. Write a query statement to create the table given above


Rollno integer primary key, Student_Name string 30
characters, Class string 5 characters,Fee integer ,
Percentage integer
2. Write a query statement to insert the following record into the
existing table “Student”
(5, “Ravi”, “XI”, 4800, 91)
3. Write a query to Display all the records of table student.
4. Write a query to Display Roll Number, Name and Class of
table Student
5. Write a query to Display records of students of class X.
6. Write a query to Display details of Sumit.
7. Write a query to Display records of student paying fees less
than 3000.
8. Write a query to Display fee of Amit
Select fee from table where name=”Amit”;
9. Write a query to Display the structure of table student desc
student;
VELAMMAL VIDHYASHRAM SURAPET – CH-66. 4. Write the following missing statements to complete the code: Table:
student
Grade 12A5 SLIP TEST Subject: Computer Science Statement 1 – to form the cursor object
1. A resultset is extracted from the database using the cursor object (that Statement 2 – to execute the query that extracts records of those students
has been already created) by giving the following statement. whose marks are greater than 75.
Mydata=cursor.fetchone() Statement 3- to read the complete result of the query (records whose 12
(a) How many records will be returned by fetchone() method? marks are greater than 75) into the object named data, from the table
(b) What will be the datatype of Mydata object after the given command student in the database.
is executed? import mysql.connector as mysql
2. To establish a connection between Python and SQL database, connect() def sql_data():
is used. Which of the following arguments may not necessarily be given con1=mysql.connect(host="localhost",user="root",
while calling connect() ? password="tiger", database="school"
(a) host (b) database (c) user mycursor=_______________ #Statement 1
(d) password print("Students with marks greater than 75 are :
3. Write the following missing statements to complete the code: ______________________ #Statement 2
Statement 1 – to form the cursor object data=__________________ #Statement 3
Statement 2 – to execute the command that inserts the record in the table for i in data:
Student. print(i)
Statement 3- to add the record permanently in the database print()
import mysql.connector as mysql 5. Consider the following Python code is written to access the record of
def sql_data(): CODE passed to function: Complete the missing statements:
def Search(eno): #Assume basic setup import,
con1=mysql.connect(host="localhost",user="root",password="tiger", connection and cursor is created.
database="school") query="select * from emp where empno=________".format(eno)
mycursor=_________________ #Statement 1 mycursor.execute(query)
rno=int(input("Enter Roll Number :: ")) results = mycursor._________
name=input("Enter name :: ") print(results)
clas=int(input("Enter class :: "))
marks=int(input("Enter Marks :: "))
querry="insert into
studentvalues({},'{}',{},{})".format(rno,name,clas,marks)
______________________ #Statement 2
______________________ # Statement 3
print("Data Added successfully")

You might also like