Students can Download Chapter 9 Structured Query Language Questions and Answers, Plus Two Computer Science Chapter Wise Questions and Answers helps you to revise the complete Kerala State Syllabus and score more marks in your examinations
Kerala Plus Two Computer Science Chapter Wise Questions and Answers Chapter 9 Structured Query Language
Plus Two Computer Science Structured Query Language One Mark Questions and Answers
………………. form of SQL is designed for use within general purpose programming languages such as COBOL, C, etc.
What is TCL?
Transaction Control Language- component of SQL includes commands for specifying transactions.
Data dictionary is a special file in DBMS. What is it used for?
Table details are stored in this file.
What does the following statement mean?
Field Name can store up to 30 characters. It is a column definition.
Is there any data type available in SQL to store your date of birth information?
Yes. DATE data type
Pick the odd one out.
(DEC, NUMBER, INT, DATE)
How do you ensure that the field ‘name’ will have some value always?
using the constraint NOT NULL.
How to set the default value of column District in a table to Thrissur?
District VARCHAR(30) DEFAULT ‘Thrissur’
…………… symbol is used as substitution operator in SQL.
Is there any method to find the strings starting with letter ‘a’ from a field in SQL?
Use LIKE operator, LIKE ‘a%’
How to check whether a particular field contains null values or not?
Use operator IS NULL
‘ORDER BY’ clause is used for …………
Sorting the results of a query by ascending(Asc) or Descending (Desc)
The built-in functions in SQL that return just a single value for a group of rows in a table are called ………..
Summary functions or aggregate functions
How to find the number of values in a column in the table?
Using the function COUNT()
………………. is the clause in SQL used for categorization.
Thomas wants to remove a table that he were using. How could you help him doing this?
Using DROP TABLE command.
Pick the odd one out.
(SELECT, UPDATE, DELETE, DROP TABLE)
Name the aggregate function that can be used to find the total number of records.
Which of the following is an essential clause used with SELECT command?
(GROUP BY, ORDER BY, WHERE, FROM)
Which of the following is not a column constraint?
(CHECK, DISTINCT, UNIQUE, DEFAULT)
Which of the following is a DDL command?
(SELECT, UPDATE, CREATE TABLE, INSERT INTO)
What are the logical operators used in SQL?
And, Or, Not.
The …………. operator pf SQL is used to match a pattern with the help of %. February 2009
The structure of a table Book is given below.
Write SQL query to Insert an additional column Purchase date of date type to the Books table.
Alter table Book add(PurchaseDate Date);
Suppose we want to include a column in a table in which serial numbers are to be stored automatically on adding new records. Which constraint is to be used for that column during table creation?
The constraint Autojncrement is used.
Which of the following cannot be used to name a table in SQL? Give the reason.
(b) Table. This is a keyword hence it cannot be used.
Which of the following commands is used to view the structure of a table?
(a) SHOW TABLES
The command to eliminate the table CUSTOMER from a database is:
(a) REMOVE TABLE CUSTOMER
(b) DROP TABLE CUSTOMER
(c) DELETE TABLE CUSTOMER
(d) UPDATE TABLE CUSTOMER
(b) DROP TABLE CUSTOMER
Which SQL command is used to open a database?
Which is the keyword used with SELECT command to avoid duplication of rows in the selection?
Pick odd one out and write reason:
(b) ORDER BY
(d) GROUP BY
UPDATE. It is a command and others are clauses.
Which of the following clause is not used with SELECT command in SQL?
(a) GROUP BY
(d) ORDER BY
(c) SET. This clause is used with UPDATE.
……………… operator in SQL is used with wild card characters for selection of records.
(c) NOT IN
(d) IN and NOT IN
Plus Two Computer Science Structured Query Language Two Mark Questions and Answers
How is SQL different from other computer high-level languages?
SQL means Structured Query Language. It is a relational database language, not a programming language like other high-level languages. It provides facilities to create a table, insert data into a table, retrieve information from a table, modify data in the table, etc.
Distinguish the SQL keywords UNIQUE and DISTINCT.
1. Unique – It ensures that no two rows have the same value in a column while storing data. It is used with create command.
2. Distinct – This keyword is used to avoid duplicate values in a column of a table while retrieving data. It is used with select command.
Identify errors in the following SQL statement and rewrite it correctly. Underline the corrections.
CREATE student TABLE (admno PRIMARY KEY, roll no INT, name CHAR);
The correct SQL statement is as follows.
CREATE TABLE student( admno INT PRIMARY KEY, roll_no INT, name CHAR(3));
Suppose a column named Fee does not contain any value for some records in the table named STUDENT. Write SQL statements to fill these blanks with 1000.
UPDATE STUDENT SET Fee = 1000 WHERE Fee IS NULL;
Identify the errors in the following SQL statement and give reason for the error.
SELECT FROM STUDENT ORDER BY Group WHERE Marks above 50;
In this query Group is the keyword hence it cannot be used. The correct query is as follows.
SELECT * FROM STUDENT WHERE Marks > 50 ORDER BY Marks;
Differentiate CHAR and VARCHAR data types of SQL.
- Char – It is used to store fixed number of characters. It is declared as char(size).
- Varchar – It is used to store characters but it uses only enough memory.
Assume that CUSTOMER is a table with columns Cust_code, Cust_name, Mob_No and Email. Write an SQL statement to add the details of a customer who has no e-mail id.
INSERT INTO CUSTOMER VALUES(1001, ‘ALVIS’, 9447024365, NULL);
Find the correct clause from the 2nd column for each SQL command in the 1st column.
Is ALL a keyword in SQL? Explain
Yes, ALL retains all the duplicate values of a field
Differentiate LIKE ‘a%’ and LiKE ‘a_’
%, it replaces a string but _ replaces only one character at a time.LIKE ‘a%’ retrieve all strings of any length that start with letter ‘a’ while LIKE ‘a_’ retrieve all two letter strings that start with letter ‘a’.
Is multiple sorting possible using ORDER BY clause? Explain
Yes, by giving multiple field names separated by comma in the ORDER BY clause.
While inserting records into a table, Raju finds it is not possible to give more than 20 characters in the ‘name’ field. How can you help Raju solve this problem?
Using ALTER TABLE command he can modify the width of field so that it can accommodate more than 20 characters.
After executing a query Mohan gets a message like ‘Table Altered’. What would have he done? Give the syntax.
He would have used the ALTER TABLE command.
Syntax: ALTER TABLE ADD/MODIFY ();
During discussion one student said that DELETE and DROP TABLE commands are same. Do you agree with that? Justify.
No, DROP TABLE removes a table entirely from the database whereas DELETE command deletes only records from an existing table.
1. Pick odd one out.
DROP TABLE, DELETE, ALTER TABLE, CREATE VIEW
2. Justify your answer
- All others are DDL commands
- Pick odd one out from the following.
- Justify your answer.
- Group By
- Group By is not a Constraint.
Consider the following SQL statements.
Where name = ‘Raju”
Find the error in the SQL if any and correct it.
Delete from student where name = ‘Raju’
Consider the following Query in SQL.
From Employee Where branch = ‘Kannur’ Group By Department Having avg (salary) > 7000, Compare the ‘where’ clause and ‘Having’ Clause using the above query.
‘where’ clause applies on single rows but Having clause applies on a group.
Some constraints in SQL are called column constraints. Some constraints are called table constraints. How do they differ?
Column constraints are specified while defining each column, table constraints are specified once for the entire table at the end of table definition
1. Choose the odd one from the following.
Primary key, Unique, Distinct, Default, Check
2. Justify your choice
- Distinct is used with select command while others are column constraints of create table command.
Name the most appropriate SQL data type required to store the following data.
- Name of a student
- Date of Birth of a student.
- RollNo. of a student (in the range 1 to 50)
- Percentage of marks obtained
- Smallint OR Integer Or decimal
- Dec(5, 2)
1. From the list given below select the names that cannot be used as a table name.
Adm_No, Date, Salary2006, Table, Column_Name, Address.
2. Justify your selection.
- Date, Table
- There is a data type Date and Table is a keyword used to create a table. So these two are not used.
Classify the following SQL elements into two and give proper title for each category.
NOT NULL, AVG, COUNT, CHECK, SUM, DEFAULT
Plus Two Computer Science Structured Query Language Three Mark Questions and Answers
As a part of your school project, you are asked to create a table Student with the fields RollNo, Name, Date of Birth and Score in IT. The constraints required are RollNo. is the primary key. Name cannot be empty.
Create table student(RollNo decimal(2) not null primary key, Name varchar(20) not null, DOB date, Score number(2));
A table Employee consists of fields EmployeeNo, Name, Designation and Salary.
Consider that you are forced to give access to this table for an engineer from another company. But for security reasons you need to hide Salary from him. Employee No, Name, Designation, Salary.
- Name the concept that provides this engineer, a facility to work on this table without viewing salary. Salary view
- Write SQL query for implementing this SQL query
- Create view Empview as select employeeno, Name, Designation from Employee.
Explain the keywords in the following query.
SELECT allows to retrieve a subset of rows from the table, DISTINCT avoids duplication of courses from the table STUDENT, FROM is a keyword used to specify the name of the table
A table named student is given below.
Write answers for the questions based on the above table.
- SQL statement to display the different courses available without duplication.
- SQL statement to display the Name and Batch of the students whose percentage has a null value.
- Output of the query select count (percentage) from Student.
- Select distinct batch from Student;
- Select name, batch from Student where percent is null
Once the creation of a table is over, one can perform two changes in the schema of the table. What are they? Give syntax.
We can alter the table in two ways.
1. We can add a new column to the existing table using the following
syntax: ALTER TABLE ADD( );
2. We can also change or modify the existing column in terms of type or size using the following
syntax: ALTER TABLEMODIFY( );
Explain how pattern matching can be done in SQL with an example.
pattern matching can be done using the operator LIKE while setting the condition with pattern matching. for eg., to display the names of all students whose name begins with letters ‘ma’, we can write the following query, SELECT name FROM STUDENT WHERE name LIKE ‘ma%’; here the character ‘%’ – substitutes any number of characters in the value of the specified column. Another character substitutes only one character of the specified column.
During the discussion of study your friend say that table and view are the same. How can you correct him?
Tables and views are different. A view is a single virtual table that is derived from other physically existing tables. When we access a view we actually access the base tables.
We can use all the DML commands with the views but care should be taken as operation actually reflects in the base tables. The advantage of view is that without sparing extra storage space, we can use same table as different virtual tables. It also implements sharing along with privacy.
Find the errors if any of the following code.
Create table emp (name char, RolINo int(20));
Here the argument size of data type char of field name is missing. So we can store a character only. The second error is the data type int has no argument. The correct statement is as follows Create table emp (name char(20), RolINo int);
Consider the following variable Declaration in SQL.
a. name char (25)
b. name Varchar (25)
- Considering the utilisation of memory, which variable declaration is more suitable.
- Justify your answer
1. name varchar (25)
2. Because char data type is fixed length. It allocates maximum memory i.e, here it allocates memory for 25 characters maybe there is a chance of memory wastage. But Varchar allocates only enough memory to store the actual size.
Mr. Dilip wants to construct a table and implement some restrictions on the table.
- Column can never have empty values.
- One of the columns must be a key to identify the rows etc.
Can you help him to create that table satisfying the above restrictions with an example
- Use of create table, Not NULL.
- Primary key Eg: Create table employee(RollNo decimal(3) not null primary key,Name Varchar(70) not null, Design Varchar(30), DOB Date,Salary Dec(7,2));
Write SQL query to construct a table student with fields Reg No, Stud Name, Sex, Course, grade, etc. As per the following conditions
- Reg No should not be empty and using this column any rows in that table can be identified. Reg. No.
- Student name should have some value.
- Default value of sex be Female.
- Grade should be any of the values: A+, A, B+, B, C+, C, D+, D, E
Create table Student(RollNo decimal(3) not null primary key, Name Varchar(70) not null, sex char default ‘Female’,Grade char(2));
Ramu create Table employee with fields empId, empname, Designation, salary using SQL statements. Later he found that data type of emPId is typed as Integer instead of character and missed a field ‘Department’. Can you help him to solve this problem without recreating ‘employee’ table?
Alter Table Employee Modify(Empld char(4)); AlterTable Employee Add(Dept char(15));
While creating a table Alvis give “Emp Details” for table name. Is it Possible? Write down the rules for naming a Table.
It is not possible because there is a space between Emp and Details. The rules are given below:
- It must not be a keyword(Keywords are reserved words and have predefined meaning)
- It must begin with alphabets
- Digits can be used followed by alphabets
- Special characters cannot be used except underscore
- We cannot give the name of another table
Plus Two Computer Science Structured Query Language Five Mark Questions and Answers
Consider the table ITEMS.
a) SELECT ITEMCODE, NAME FROM ITEMS WHERE CATEGORY = ‘Stationery’;
b) SELECT * FROM ITEMS WHERE SALES_ PRICE < UNIT_PRICE;
c) SELECT CATEGORY, COUNT(*) FROM ITEMS GROUP BY CATEGORY;
Write SQL queries to SQL Query to
1. Create a table Employee with the fields given below.
2. List the name of all employees whose name’s second letter is ‘a’.
3. List the Name and Designation of employees whose Designation is not ‘Manager’
4. Increase the salary of ail employees by 10 percent.
5. Remove all managers whose salary is less than Rs. 10,000 from the table.
- Create table employee(Name Varchar(70), Desgn Varchar(30), DOB Date, Salary Dec(7,2));
- Select Name from Employee where Name like
- Select Name, Desgn from Employee where Desg no’Manager’;
- Update Employee set Salary = Salary + Salary * .01;
- Delete from Employee where Desgn = ‘Manager’ and Salary < 10000;
A table Student consists of fields Roll No, Name, Batch and Percent. Write SQL statements to
- Display RolINo and Name of students whose percentage is Iessthan90 and greater than 70.
- Display RolINo and Name of all students in science batch whose percentage is more than 90.
- Display Names of all students in commerce and science batches.
- Display the average Percent of students in each batch.
- Display RolINo and Name in the ascending order of Batch and descending order of Percent.
- Select RollNo, Name from Student where percent < 90 and percent > 70;
- Select RollNo, Name from Student where Batch = ’Science’ and percent > 90;
- Select Name from Student where batch = ’Science’ Or ’batchCommerce’;
- Select batch, Avg(percent) from Student group by batch;
- Select RollNo, Name from Student order by batch, percent desc;
1. Classify the following SQL commands.
Create table, Insert Into, AlterTable, Delete, Up-date, Drop Table, Select.
2. List the features of each category.
1. DDL – Create Table, Alter Table, Drop Table.
DML- Insert Into, Delete, Update, Select.
2. DDL – DDL means Data Definition Language. It is used to create the structure of a table, modify the structure of a table and delete the structure of a table. DML -DML means Data Manipulation Language. It is used to insert records into a table, modify the records of a table, delete the records of a table and retrieve the records from a table.
Explain the available database integrity constraints.
1. NOT NULL: it specifies that a column can never have null values, i.e., not empty
2. UNIQUE: it ensures that no two rows have same value in the specified column.
3. PRIMARY KEY: it declares a column or a set of columns as the primary key of the table. This constraint makes a column NOT NULL and UNIQUE.
4. DEFAULT: it sets a default value for a column when the user does not enter a value for that column.
5. Auto_increment: This constraint is used to perform auto increment the values in a column. That automatically generates serial numbers. Only one auto-increment column per table is allowed.
Consider a table student with fields Reg No, Stud Name, Sex, Course, total score.
Write SQL queries for the following:
RegNo, Studname, Sex, Course, Total score.
- Enter a Record
- List the Detail’s of all students
- Display Details of the student whose name ends with ‘Kumar’.
- List all Female students who got more than 50 marks.
- List all students who are studying either science or in Commerce group.
- List details of those students who are studying Humanities in the Descending order of their names.
- Insert into Student values (52, ‘JOSE’, ‘Male’, ‘Science’, 500);
- Select*from Student;
- Select* from Student where name like ’%Kumar’;
- Select * from Student where sex=’Female’ and Total >50;
- Select * from Student where course = ‘science’ or course =‘commerce’;
- Select* from Student where course-‘Humanities’ order by name desc;
Construct a Table Product with the following fields using SQL.
Product code – Consist of Alphanumeric code.
Product name – Consist of maximum of 30 Alphabets
Unit price – Numeric values
Quantity – Numeric values
Product price – Numeric Values
Write Query for the following:
- Enter 5 records in the table (not give values for product prices)
- Calculate product price (unit price × quantity)
- List all product whose unit price ranging from 10 to 20
- Calculate total price of all products.
Create table Product(ProdCode Varchar(20) not null primary key, ProdName char(30), UPrice decimal(7,2), Qty decimal(6), ProdPrice decimal(7,2));
- Insert into Product(Product Code,Product Name, Unit Price, Quantity) values (‘101 ’, ‘LUX’, 29.50,500); Similarly insert four more records
- Update Product set ProdPrice=Qty * UPrice;
- Select ProdName from Product where UPrice be-tween 10 and 20;
- Select sum(ProdPrice) from Product;
Mr. Wilson wants to store the details of students. The details consist of different types of data. Explain different data types used in SQL to store data.
The different data types are
1. Char (Fixed):
It is declared as char (size). This data type is used to store alphanumeric characters. We have to specify the size. If no size is specified, by default we can store only one character. Eg: name char(20)
2. Variable Character:
It is declared as varchar (size). This data type is also used to store alphanumeric characters. But there is a slight difference. lt allocates only enough memory to store the actual size.
Eg: name varchar(20)
It is declared as Dec(size, scale), where size is the number of digits and scale is the maximum number of digits to the right of the decimal point.
Eg: weight dec(3, 2)
It is declared as int. It does not have any arguments. It takes more memory. Eg: ROllNO int.
5. Small Integer:
It is declared as smallint. It takes less memory ROllNO int.
It is used to store date. Eg: DOB date.
It is used to store time. Eg: Joining_Time Time.
A company wants to create a table to store its employees details. Write SQL Commands for the following :
- Create a table with EMP table having fields EMPNO primary key varchar(10), Name varchar(20), Salary number(6), Department varchar(3)
- Insert values to table
- List all employees whose salary > 10,000 Salary 10,000
- Display name and salary in the order of name.
- Create table EMP (EMPNO varchar(10) not null primary key, Name varchar(20), Salary decimal(6), Deptvarchar(3));
- Insert into EMP values (‘1001 ’, ‘ALVIS’, 50000, ‘Sales’);
- Select * from EMP where salary > 10000;
- Select name, salary from EMP order by name;
Create a table ‘Savings’ with the following fields. Acc No (Integer), Name (char), age (Integer) and balance (Number) where Acc No is the primary key. Write SQL commands for the following.
- Insert data in all the fields for 3 records inserted
- Display the list of account holders in the ascending order Of their names.
- Display the list of all account holders having age between 20 and 30
- Display the name and Acc No of customers having a balance > 10 lakhs
Create table Savings(Accno decimal(4) not null primary key, name char(2), age decimal(3), Balance decimal(8, 2));
- Insert into savings values (501, ‘Andrea’, 18,45000)
- Select * from Savings order by name
- Select * from Savings where age between 20 and 30
- Select name.accno from Savings where balance >100000
Which are the components of SQL? How do they help to manage database?
The components of SQL are given below.
a. DDL commands ( 3 commands):
- Create table – Used to create a table.
- Alter table – Used to modify existing column or add new column to an existing table. There are 2 keywords used ADD and MODIFY.
- Drop table – Used to remove a table from the memory.
b. DML commands ( 4 commands):
- Select – Used to select rows from a table. The keyword From is used with this. Where clause is used to specify the condition.
- Insert – Used to insert new records into a table. So the keyword used is INTO.
- Delete – Used to delete records in a table.
- Update – Used to modify the records in a table the keyword used is set.
c. DCL (Data Control Language) commands:
- Grant – It grants permission to the users to the database
- Revoke – It withdraws user’s rights given by using Grant command