CBSE Class XI Informatics Practices Introduction To Mysql Questions-Unlocked
CBSE Class XI Informatics Practices Introduction To Mysql Questions-Unlocked
com
Ans . SQL is Non-procedural universal data access language used to access and manipulate data stored in nearly all
the data bases available currently. SQL standards are defined by ANSI (American National Standards Institute). SQL
statements are used to retrieve and update data in a database. SQL works with database programs like MySQL, MS
Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.
m
create, destroy, or restructure databases and tables come under this category. Examples of DDL commands are -
co
CREATE, DROP, ALTER. Data Manipulation Language (DML): This is a category of SQL commands. All the
commands which are used to manipulate data within tables come under this category. Examples of DML commands
are - INSERT, UPDATE, DELETE.
y.
da
Q.4 What is a constraint?
to
Example: NOT NULL (ensure that column con not have null value), CHECK (make sure that all
di
value satisfy certain criteria), UNIQUE (ensure that all values in a column are different) etc.
tu
Ans: Single Row Function work with a single row at a time. A single row function returns a result for
w
Examples of Single row functions are Sqrt(), Concat(), Lcase(), Upper(), Day(), etc.
Ans. The CHAR data-type stores fixed length strings such that strings having length smaller than the
field size are padded on the right with spaces before being stored.
The VARCHAR on the other hand supports variable length strings and therefore stores strings
Q.7 What are the differences between DELETE and DROP commands of SQL?
Ans: DELETE is DML command while DROP is a DDL command. Delete is used to delete
rows from a table while DROP is used to remove the entire table from the database.
Ans:MySQL server listens for clients requests coming in over the network and accesses database contents
according to those requests and provides that to the client.
Ans:MySQL Clients are programs that connect to MySQL Server and issue queries in predefined format.
Q.10 Explain with the help of an example that why should a transaction be executed as a
Ans: Suppose Raunak's account number is 3246 and his aunt's account number is 5135. In order
to process the cheque presented by Raunak, the following two SQL commands need to be
m
UPDATE Savings SET balance = balance + 2000
co
WHERE account_no = 3246;
The above two Updates should both take place. If the first Update takes place and there is
y.
da
a system failure, the first updation should be undone. Either both the updations should be done and if
it is not possible for both the updations to be done, then no updation should be done.
to
es
di
tu
.s
w
w
w
2. A table "Animals" in a database has 3 columns and 10 records. What is the degree and
m
cardinality of this table?
co
Ans: Degree 3 and Cardinality=10
3. Answer the question based on the table VOTER given below:
Table : VOTER
y.
da
Column Name Data type Size Constraints Description
to
(i) Write the command to delete all the rows of particular voter from the table voter where voter ID between
w
10 and 20.
Ans: Delete from VOTER where V_id between 10 and 20;
(ii) Delete the table physically.
Ans: Drop table VOTER;
4. . Write MySql command to create a furniture table including all constraint.
Table: Furniture
Table: Loan_Accounts
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
1 R.K. Gupta 300000 36 12.00 19-07-2009
2 S.P. Sharma 500000 48 10.00 22-03-2008
3 K.P. Jain 300000 36 NULL 08-03-2007
4 M.P. Yadav 800000 60 10.00 06-12-2008
5 S.P. Sinha 200000 36 12.50 03-01-2010
6 P. Sharma 700000 60 12.50 05-06-2008
7 K.S. Dhall 500000 48 NULL 05-03-2008
m
Mysql> Create Database LOANS;
co
2. Use the database LOANS.
Mysql> Use LOANS;
Create Table / Insert Into y.
da
3. Create the table Loan_Accounts and insert tuples in it.
to
m
of instalments 36.
co
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Instalment <>36;
14. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount
is less than 500000 or int_rate is more than 12.
y.
da
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Loan_Amount <500000 or
Int_rate>12;
to
15. Display the details of all the loans which started in the year 2009.
es
500000.
tu
Mysql> Select * from Loan_Acc where Loan_Amount between 400000 and 50000;
.s
17. Display the details of all the loans whose rate of interest is in the range 11% to 12%.
w
Using IN Operator
19. Display the Cust_Name and Loan_Amount for all the loans for which the number of
instalments are 24, 36, or 48. (Using IN operator)
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Instalment IN(24,36,48); UR
Using LIKE Operator
20. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name ends with 'Sharma'.
Mysql> Select AccNo, Cust_name from Loan_Acc where
Cust_Name like '%Sharma';
21. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name ends
with 'a'.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where Cust_Name like '%a';
22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a'
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where
Downloaded from www.studiestoday.com
Downloaded from www.studiestoday.com
Cust_Name like '%a%';
23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name does not contain 'P'.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where
NOT (Cust_Name like '%P%');
24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a' as the second last character.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where
Cust_Name like '%a_';
m
29. Display the details of all the loans in the ascending order of their Loan_Amount and within
co
Loan_Amount in the descending order of their Start_Date.
Mysql> Select * from Loan_Acc ORDER BY Loan_Amount, Start_Date DESC;
y.
da
Using UPDATE, DELETE, ALTER TABLE
30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
to
31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than 400000.
Mysql> Update Loan_Acc SET Int_Rate= Int_Rate+0.5
di
33. Delete the records of all the loans whose start date is before 2007.
Mysql> Delete From Loan_Acc Where Year(Start_Date)<2007;
34. Delete the records of all the loans of 'K.P. Jain'
Mysql> Delete From Loan_Acc Where Cust_Name='K.P.Jain';
35. Add another column Category of type CHAR(1) in the Loan table.
Mysql> Alter Table Loan_Acc ADD (Category CHAR(1) );
Find the Output of the following queries
36.
SELECT cust_name, LENGTH(Cust_Name), LCASE(Cust_Name), UCASE(Cust_Name) FROM
Loan_Accounts WHERE Int_Rate < 11.00;
37.
SELECT LEFT(Cust_Name, 3), Right(Cust_Name, 3), SUBSTR(Cust_Name, 1, 3) FROM
Loan_Accounts WHERE Int_Rate > 10.00;
LEFT(Cust_Name, Right(Cust_Name, 3) SUBSTR(Cust_Name, 1, 3)
3)
R.K pta R.K
S.P nha S.P
P. Rma P.
RIGHT(Cust_Name, 3) SUBSTR(Cust_Name, 5)
pta Gupta
rma Sharma
m
ain Jain
co
dav Yadav
nha Sinha
rma harma y.
da
all Dhall
to
DAYOFMONTH(Start_Date)
19
tu
22
.s
08
w
06
w
03
w
05
05