Cycle Test V - Answer Key Marks: 50
Cycle Test V - Answer Key Marks: 50
Tuple: Each row in a table is known as tuple. It is also called a row/record. A single entry
in a table is called a record or row.
Example:-
.
10. Write the difference between Drop and Delete commands.
Drop – This is a DDL command. It is used to drop a table or database.
Delete – This is a DML command. It is used to delete the records/rows in a table.
Using this command we can either delete all the rows or specific rows.
DROP command is used to drop a table along with all the records stored in it whereas
DELETE command is used to delete all the records or some of the records from a table
without deleting the table.
12. Write one similarity and one difference between CHAR and VARCHAR data types.
SIMILARITY: Both CHAR and VARCHAR data types are used to store strings.
DIFFERENCE: CHAR is of fixed length but VARCHAR is of variable length
14. Write a MySql command to create the Table STOCK including its Constraints.
Table STOCK
15. What are the classification of SQL commands? Name the commands under each classification.
3
These stringx cn be written into csv files using the following 2 functions.
1. writerow() – To write one row at a time from the list using loop and iteration
2. writerows() – To write all the rows in one go without using loop/iteration
17. What is a data type? Name any 5 data types available in MySQL. Write the difference between
Numeric and Decimal data types with examples.
In SQL each column of the table is assigned a data type which conveys the kind of value that
will be stored in the column.
Data types available in MySQL – integer, float, numeric, decimal, char, varchar, date, time
18. How is alter table command used to modify the structure of the table? Write all the possibilities
in alter table command.
ALTER TABLE command is used to modify the definition (structure) of a table by modifying
the definition of its columns. The ALTER TABLE command is used to perform the following
operations:
4
type of any column or to modify its size.
(a) NOT NULL Constraint: Ensures that a column cannot have NULL value.
(b) DEFAULT Constraint: Provides a default value for a column when no value is specified.
(c) UNIQUE Constraint: Ensures that all values in a column are unique.
There should not be any redundant value in a column which is being restricted.
5
(d) PRIMARY Key: Uniquely identifies each row/record in a database table.
(e) FOREIGN Key: Uniquely identifies a row/record in any other database table.
20. What is a keyword, clause and statement/command in terms of SQL. Explain with example.
A keyword refers to an individual SQL element that has a special meaning in SQL.
For example, SELECT and FROM are keywords.
A clause is a distinct logical part of an SQL statement. Clausesbegin with a keyword for which
they are named and consist of arguments as well.
For example, SELECT empno, ename, FROM employee WHERE salary>45000, are clauses in SQL.
Here, arguments complete or modify the meaning of a clause, which is salary in the given example.
A statement or command is a combination of two or more clauses. Statements are basically
the instructions given to SQL database for executing any task.
For example, SELECT * FROM employee is an SQL statement.
An important point to remember here is that all the statements in SQL terminate with a semi-colon (;).
Also, SQL is not case sensitive; therefore, we can type commands in either upper case or lower case.
21. Ashvik, a student of class 12th, is learning CSV File Module in Python. During examination, he
has been assigned an incomplete python code (shown below) to create a CSV File 'Stud.csv' (content
shown below). Help him in completing the code which creates the desired CSV File.
CSV File
6
Location=input("Enter Loc\n")
City=input("Enter City\n")
data=[ Name, Location, City]
record.append(_____) #Statement-4
ch=input("insert more record(y/n):")
if ch=='n':
break
abc.______________(record) #Statement-5
a. Identify the suitable code for blank space in line marked as Statement-1. csv
b. Identify the missing code for blank space in line marked as Statement-2? 'Stud.csv', ‘w’
c. Write the function name (with argument) that should be used in the blank space of line marked as
Statement-3. csv.writer (csv1)
d. Identify the suitable code for blank space in the line marked as Statement-4. data
e. Write the function name that should be used in the blank space of line marked as Statement-6 to
create the desired CSV File? writerows
22. Consider the following tables Games and answer the following questions
a. Which column will be suitable to choose as a Primary Key? Justify your answer.
Gcode is suitable for primary key as it is a Games table and GCode is unique for each game
b. Write a command to create the above table structure.
CREATE TABLE GAMES(GCode int, GameName varchar(20),
Type varchar(10), Number int,
PrizeMoney int, ScheduleDate date);
c. Write a command to add a column Date_Of_Registration with the data type date.
ALTER TABLE GAMES ADD Date_Of_Registration date;
d. Write a command to insert the data (104, ‘Shuttle cock’, ‘Indoor’, 2, 10000, ‘2004-01-21’)
Insert into GAMES values (104, ‘Shuttle cock’, ‘Indoor’, 2, 10000, ‘2004-01-21’)
e. Write a command to increase the price money by 1000 for all the Indoor games.
7
UPDATE GAMES SET PrizeMoney = PrizeMoney + 1000 WHERE Type = ‘Indoor’;
********
MAHATMA MONTESSORI SCHOOL SET B
(Affiliated to Central Board of Secondary Education)
CYCLE TEST V-ANSWER KEY Marks: 50
STD:XII COMPUTER SCIENCE (Code: 083) Time: 2 Hrs
I. Choose the best answers: (5 X 1 = 5)
1. The ____ allows us to perform tasks related to changing the values of the record in a table.
b. DML
2. Mr. James created a table CLIENT with 2 rows and 4 columns. He added 2 more rows to it and deleted one
column. What is the Cardinality and Degree of the resultant Table CLIENT? d. Degree 3, Cardinality 4
3. _____ command helps us to view the structure of the table. d. Either b or c
4. CSV stands for _____. c. Comma Separated Values
5. An SQL Clause is made up of _______ . c. Keywords and Arguments
Tuple: Each row in a table is known as tuple. It is also called a row/record. A single entry
in a table is called a record or row.
Example:-
.
10. Write the difference between Alter and Update commands.
ALTER – It is a DDL command. It is used to modify the definition/structure of a table.
Using Alter command we can add, remove, change the data type/size, rename
a column.
UPDATE – It is a DML command. It is used to modify the values in the records in a
table.
Candidate Key: A candidate key refers to all the attributes in a relation that are unique
or are capable of becoming a primary key. There can be more than one
candidate key
12. Write one similarity and one difference between Decimal and Numeric data types.
SIMILARITY – Both the data types are used to define numbers with decimal places
DIFFERENCE -
9
13. Write MySQL command for the following.
(i) to list down the exiting tables in an opened database. SHOW TABLES;
(ii) to create a database named “CONTACTS” CREATE DATABASE CONTACTS;
14. Write SQL query to create a table ‘Song’ with the following structure
Table Song
ANS:
CREATE TABLE Song(Songid int Primry Key, Title Varchar(50), Duration int, ReleaseDate Date);
15. What are the classification of SQL commands? Name the commands under each classification.
10
III. Answer the following in detail: (5X 3 = 15)
17. What is a data type? Name any 5 data types available in MySQL. Write the difference between
Numeric and Decimal data types with examples.
In SQL, each column of the table is assigned a data type which conveys the kind of value that
will be stored in the column.
Data types available in MySQL – integer, float, numeric, decimal, char, varchar, date, time
11
18. What are the different ways to insert records in table? Explain with syntax and examples.
(b) Inserting data directly into a table: The second form specifies both the column names
and the values to be inserted.
Syntax: INSERT INTO table_name (column1,column2,columnN,...)
VALUES (value1,value2,valueN,...);
Here, column1, column2, ...columnN—the names of the columns in the table for which you
want to insert data.
For example, INSERT INTO student(RollNo, Name, Gender, Marks, DOB)
VALUES(2,‘Deep Singh’, ‘M’, 98, ‘1996-08-22’);
12
(c) Inserting data into specific columns of a table:
Syntax for SQL INSERT is:
INSERT INTO <table_name>[(column1, column2, ... columnN)]
values [(value1, value2,.... valueN)];
For example, to insert a record into the student table for the columns Rollno, Name and
Marks only, the SQL insert query is:
INSERT INTO student (Rollno, Name, Marks) values (4,”Radhika Gupta”,78);
19. Can you add more than one column in an existing table? If yes, explain.
Yes we can add more than one column in an existing table as follows.
Alter table tablename add column1 datatype1, column2 datatype2…..;
Ex., Alter table STUDENT ADD grade char(2), DOB date;
20. What is a keyword, clause and statement/command in terms of SQL. Explain with example.
A keyword refers to an individual SQL element that has a special meaning in SQL.
For example, SELECT and FROM are keywords.
A clause is a distinct logical part of an SQL statement. Clausesbegin with a keyword for which
they are named and consist of arguments as well.
For example, SELECT empno, ename, FROM employee WHERE salary>45000, are clauses in SQL.
Here, arguments complete or modify the meaning of a clause, which is salary in the given example.
A statement or command is a combination of two or more clauses. Statements are basically
the instructions given to SQL database for executing any task.
For example, SELECT * FROM employee is an SQL statement.
An important point to remember here is that all the statements in SQL terminate with a semi-colon (;).
Also, SQL is not case sensitive; therefore, we can type commands in either upper case or lower case.
13
f=open(“STORE.CSV”,_________) #Statement-3
fw=csv.writer(f)
fw.writerow(_____________) #Statement-4
f.close()
def ShowRecord():
NewItem=csv.___________(NI) #Statement-5
print(rec[0],“#”,rec[1])
AddItem(“Sugar”,38.0)
AddItem(“Rice”,48.50)
ShowRecord() #Statement-6
c. Fill in the blank in Statement-4 to write the item and its corresponding price into the file?
[Item, Price]
d. Which function to be used in Statement-5 to read the data from a csvfile. reader(NI)
TABLE: EMPLOYEE
14
a. Which column will be suitable to choose as a Primary Key? Justify your answer.
Ecode is suitable for primary key as it is a EMPLOYEE table and ECode is unique for each employee
b. Write a command to create the above table structure.
CREATE TABLE EMPLOYEE(ECODE INT, NAME VARCHAR(30),
DESIG VARCHAR(20), SGRADE VARCHAR(10),
DOJ DATE, DOB DATE);
c. Write a command to add a column Basic_Salaty with the data type integer.
ALTER TABLE EMPLOYEE ADD BASIC_SALARY INT;
d. Write a command to insert the data
(104, ‘Baradhwaj’, ‘Clerk’, ‘S07’, ‘2004-01-21’, ‘1985-05-31’)
INSERT INTO EMPLOYEE VALUES(104, ‘Baradhwaj’, ‘Clerk’, ‘S07’, ‘2004-01-21’,
‘1985-05-31’);
e. The employee Mr. Ravi Chander is promoted as an Executive. How will you write a
command to change his Designation in the above table.
UPDATE EMPLOYEE
SET DESIG = ‘EXECUTIVE’
WHERE NAME = ‘RAVI CHANDER’;
********
15