Database Practical Questions
Database Practical Questions
On
“Practical file”
As a part of Sr.Sec.Level,CBSE
I.T Practical
Submitted by
Miss. Srushti Mukund Bajaj
Roll No
(………………..)
Under the guidance of
Mrs.Reshma Shinde
Through
Sinhgad Public School,Korti,Pandharpur
Year
(2024-2025)
Page
1
Certificate
Mrs.Reshma Shinde
Mrs.Smita Navale
Departement of I.T.
Principal
Page
2
Internal Examiner
External Examiner
Date :- ______________
Page
3
Acknowledgement
Page
4
without which I would be unable to complete
my project.
Page
5
Declaration
Respected madam,
I undersigned hereby declare that, the
project entitled
‘Practical file’ , with special reference to
under the guidance of
to Sinhgad Public School, Korti, Pandharpur
for the part of information technology Project
work, at Sr.Sec.CBSE Level, written and
submitted by me is an original work.
Page
6
Date : …………………….
Page
7
Database Practical
Questions
Exercise 1
Q.1] Create table Sales_people with fields snum, sname,
city, commission.
Answer:-
Code & output:
Page
8
Code & output:
Page
9
Q.5] Display details of all tables sales_people, orders,
customers1.
Answer:-
Code & output:
Page
10
Q.6] Display all details of fields sname,commission.
Answer:-
Code & output:
Page
11
Q.8] Display snum of sales_people with the distinct snum.
Answer:-
Code & output:
Page
12
Q.12] Display the numbers of sales persons, with orders
currently in the orders table without any repeats.
Answer:-
Code & output:
Page
13
Exercise 2
Page
14
Q.4] Display names & cities of all salespeople in ‘Pune’
with a commission above 100.
Answer:-
Code & output:
Page
15
Code & output:
Page
16
Q.11] Display all customers records arranged on rating in
desc Order.
Answer:-
Code & output:
Page
17
Answer:-
Code & output:
Exercise 3
Q.1] Display the count of different non-NULL city values in
the customer’s table.
Answer:-
Code & output:
Page
18
Q.2] Display the maximum outstanding amount as
blnc+amt.
Answer:-
Code & output:
Page
19
Q.5] Display sales persons number wise maximum amt
from orders table.
Answer:-
Code & output:
Page
20
Q.9] Display customer’s highest ratings in each city.
Answer:-
Code & output:
Q.10] Write a query that totals the orders for each day &
places the Results in descending order.
Answer:-
Code & output:
Page
21
Q.12] Increment wise commission of all sales persons by
200.
Answer:-
Code & output:
Page
22
Q.15] Display the names & cities of all customers with
same rating as ‘Anjali’.
Answer:-
Code & output:
Exercise 4
Q.1] Write a query that selects the total amt in orders for
each Salesperson for whom this total is greater than the
amount of The largest order in table.
Answer:-
Code & output:
Page
23
Q.3] Create a union of two queries that shoes the
names,cities & rating Of all customres. Those with a
ratings of 200 or greater will also have ratings “High
rating”, while the orders will have the words “Low rating”.
Answer:-
Code & output:
Page
24
Q.6] Create a view that shows number of salespeople in
each city.
Answer:-
Code & output:
Page
25
Q.8] Find all orders by customers not located in same
cities as their Salespersons.
Answer:-
Code & output:
Page
26
Q.11] Display the pairs of salespeople who are living in
the same city.Exclude combinations of sales people with
themselves as well as duplicate rows with the order
reversed.
Answer:-
Code & output:
Page
27
Q.14] Write a command that produces the name &
number of each salesperson & each customer with more
than one current order. Put results in Alphabetic order.
Answer:-
Code & output:
staffNo, branchNo)
Page
28
Client (clientNo, fName, lName, telNo, prefType, maxRent)
Answer:-
Codes & outputs:
Page
29
Exercise 5
Q.1] Create a database in MYSQL with suitable name,
open database.
Answer:-
Page
30
Code & output:
Page
31
Q.5] Write a query to view the structure of table.
Answer:-
Code & output:
Page
32
Answer:-
Code& output:
Page
33
Q.10] Create a query for applying check constraint.
Answer:-
Code & output:
Page
34
Page
35
Q.12] Alter table commands. Create a command to
remove NOT NULL.
Answer:-
Code & output:
Page
36
Answer:-
Code & output:
Page
37
ii.
iii.
Exercise 6
Q.1] How to display details from table with all keyword.
Page
38
Answer:-
Code & output:
Page
39
I.
II.
III.
Page
40
Answer:-
Code & output:
Page
41
Q.8] Create a query to display name of employee and his
date of birth name the output fields with alias ‘Name of
Employee’ and ‘Date of Birth’ respectively.
Answer:-
Code & output:
Page
42
Answer:-
Code & output:
Page
43
Code & output:
Page
44
Q.15] Refer table employee and dept create foreign key
on employee table on referential action, on delete set
null, on update cascade.
Answer:-
Code & output:
Page
45
Page
46
Java NetBeans Practical
Questions
Q.1] Design a Java Application using java class to wish
good morning to everyone
Answer:-
Code:
public static void main(String[] args){
System.out.print("Good morning");
}
Output:
Page
47
Scanner scanner=new Scanner(System.in);
String[] productName=new String[5];
double[] price=new double[5];
int[] quantity=new int[5];
double grossTotal=0;
for(int i=0;i<5;i++)
{
System.out.println("Enter Product" + (i+1) +
"details : ");
System.out.print("Name :");
productName[i]=scanner.nextLine();
System.out.print("Price :");
price[i]=scanner.nextDouble();
System.out.print("Quantity :");
quantity[i]=scanner.nextInt();
scanner.nextLine();
double subtotal=price[i]*quantity[i];
grossTotal += subtotal;
System.out.println();
Page
48
//display product list and grossTotal
System.out.println("Product List :");
for(int a=0;i<5;i++)
{
System.out.print((i+1)+"."+productName[i]+"-
Price :"+price[i]+"-Quantity :"+quantity[i]);
}
System.out.println("Gross Total :" +grossTotal);
}}}
Output :
Page
49
{
Scanner scanner=new Scanner(System.in);
System.out.println("Enter Student Name :");
String name=scanner.nextLine();
System.out.println("Enter marks(out of 100):");
int marks=scanner.nextInt();
String grade=calculateGrade(marks);
System.out.println("\nResult:");
System.out.println("\nName:"+name);
System.out.println("\nMarks:"+ marks);
System.out.println("\nGrade:"+grade);
scanner.close();
}
public static String calculateGrade(int marks)
{
if(marks>=90)
{
return"A1";
}
else if(marks>=80)
Page
50
{
return"A2";
}
else if(marks>=70)
{
return"B1";
}
else if(marks>=60)
{
return"B2";
}
else if(marks>=50)
{
return"C1";
}
else if(marks>=40)
{
return"C2";
}
else {
return"fail";
Page
51
}}}
Output :
Page
52
case 'i':
case 'o':
case 'u':
System.out.println(letter+"is a vowel");
break;
default:
if(letter>='a'&&letter<='z')
{
System.out.println(letter+"is a consonant");
}
else{
System.out.println("Invaild input.Please enter
a letter");
} }
scanner.close();
}}
Output :
Page
53
Answer:-
Code :
import java.util.Scanner;
public class FactorialCalculator {
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
System.out.println("Enter a number:");
int number=scanner.nextInt();
long factorial=calculateFactorial(number);
if(factorial!=1){
System.out.println("Factorial
of:"+number+"="+factorial);
}
else{
System.out.println("Factorial is not defined for
negative numbers");
}
scanner.close();
}
Page
54
public static long calculateFactorial(int number)
{
if(number<0){
return -1;
}
else if(number==10 || number==1){
return 1;
}
else{
long factorial=1;
for(int i=2;i<=number;i++){
factorial=1;
}
return factorial;
}}}
Output :
Page
55
Answer:-
Code :
import java.util.Scanner;
public class MarksCalculator {
private String[] subjectNames=new String[5];
private int[] marks=new int[5];
private int totalMarks;
private double percentage;
Page
56
}
scanner.close();
}
public void calculateTotalMarks(){
totalMarks=0;
for(int mark:marks){
totalMarks+=mark;
}
}
public void calculatePercentage(){
percentage=(double)totalMarks/5;
}
public void displayResult(){
System.out.println("\nResult:");
for(int i=0;i<5;i++){
System.out.println(subjectNames[i] +" : "
+marks[i]);
}
System.out.println("Total Marks:"+ totalMarks);
System.out.printf("Percentage:%.2f%%
%n",percentage);
Page
57
}
public static void main(String args[]){
MarksCalculator calculator=new MarksCalculator();
calculator.inputMarks();
calculator.calculateTotalMarks();
calculator.calculatePercentage();
calculator.displayResult();
}
}
Output :
Page
58
To get the length of specified string.
Answer:-
Code :
public class StringOperations {
private String inputString;
System.out.println("Uppercase:"+inputString.toUppe
rCase());
System.out.println("Lowercase:"+inputString.toLowe
rCase());
}
Page
59
System.out.println("Length of
String:"+inputString.length());
}
Page
60
public void run(){
System.out.println("My thread is in running
state.");
}
public static void main(String args[]){
threadsDemo obj=new threadsDemo();
threadsDemo obj1=new threadsDemo();
obj.start();
obj1.start();
}
}
public class MultiThreadingDemo {
public void run(){
for(int i=0;i<=5;i++){
System.out.println("My Thread is in running
state."+ i);
}
}
public static void main(String args[])
{
MultiThreadingDemo obj=new
MultiThreadingDemo();
Thread tobj=new Thread((Runnable) obj);
tobj.start();
}
}
Output:
Page
61
Q.9] Write a program to accept 10 students marks by
using arrays, display that marks. Use suitable datatype if
any if marks are below 35 give error message(assertion).
Answer:-
Code :
import java.util.Scanner;
public class StudentMarks {
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
int[] marks=new int[10];
for(int i=0;i<10;i++){
System.out.print("Enter marks for student "+
(i+1)+":");
marks[i]=scanner.nextInt();
assert marks[i]>=35:"Error:Marks cannot be
below 35";
}
System.out.println("\nStudent Marks:");
Page
62
for(int i=0;i<10;i++){
System.out.println("Student"+(i+1)+":"+marks[i]);
}
scanner.close();
}
}
Output :
Page
63
int[] numbers={1,2,3,4,5,6,7,8,9,10};
System.out.println("Index\tNumbers");
System.out.println("--------------");
for(int i=0;i<numbers.length;i++)
{
System.out.println(i+"\t"+numbers[i]);
}
}
}
Output :
Page
64
Code :
public class Author {
public int authorid;
private String authorName;
private String Bookname;
private float price;
public Author()
{
authorid=0;
authorName=" ";
Bookname=" ";
price=0;
}
public Author(int r,String s,String f,float p)
{
authorid=r;
authorName=f;
Bookname=f;
price=p;
}
Page
65
public static void main(String args[])
{
Author a1=new Author(10237,"Aman
Sharma","Mukesh Sharma",100.5f);
a1.display();
}}
Q.12] Create a user defined method to find whether the
number 105 appears in the given Array or not.(The Array
has 100,102,105,118,119,123,130,114,106).
Answer:-
Code:
public class Main {
public static void main(String args[])
{
int[] array={100,102,105,11,119,123,130,114,106};
int target=105;
boolean result=findNumber(array,target);
System.out.println("Does"+target+"exist in the
array");
}
public static boolean findNumber(int[] array,int target)
{
Page
66
for(int num:array)
{
if(num==target){
return true;
}
}
return false;
}
}
Output :
Page
67
series[0]=1;
for(int i=1;i<n;i++)
{
series[i]=series[i-1]+i+1;
}
System.out.println("Series: ");
for(int num:series)
{
System.out.print(num+"");
}
}
}
Output:
Page
68
public class ReverseString {
public static void main(String args[])
{
String str1="Sinhgad" , str2=" ";
char ch;
System.out.println("Original string is :"+str1);
for(int i=0;i<str1.length();i++){
ch=str1.charAt(i);
str2=ch+str2;
System.out.println(str2);
}
}
}
Output :
Page
69
public class extra_program {
public int a;
public int b;
public extra_program(){
a=0;
b=0;
}
static void extra_program(int a,int b){
a=16;
b=78;
}
public static void main(String args[]){
extra_program x=new extra_program();
extra_program a=new extra_program();
extra_program b=new extra_program();
System.out.println("The value of a is"+a);
System.out.println("The value of b is"+b);
}
}
Output :
Page
70
Q.16] Write a program to check do while loop.
Answer:-
Code :
import java.util.Scanner;
import java.lang.String;
public class doWhileloop {
public static void main(String args[]){
int total=1;
Scanner s=new Scanner(System.in);
System.out.println("Enter the number to find
factorial");
int fact=s.nextInt();
for(int i=1;i<=fact;i++){
total=total*i;
}
System.out.println("Factorial of "+fact+"is "+total);
}
}
Page
71
Output :
Page
72
Answer:-
Code :
import java.util.Scanner;
public class SumOfNumbers {
static int sum(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter first no");
int a=Integer.parseInt(sc.next());
System.out.println("Enter second no");
int b=Integer.parseInt(sc.next());
System.out.println("Enter third no");
int c=Integer.parseInt(sc.next());
int s=a+b+c;
return s;
}
public static void main(String args[]){
int t=sum();
System.out.println("Total is "+t);
}
}
Output :
Page
73
Code :
public class Palinder {
private static boolean is;
public static boolean isPalinder(String str){
String rev=" ";
boolean answer=false;
for(int i=str.length()-1;i>=0;i--){
rev=rev+str.charAt(i);
}
if(str.equals(rev)){
answer=true;
}
return answer;
}
public static void main(String args[]){
String str="racercar";
str=str.toLowerCase();
boolean a;
a=isPalinder(str);
System.out.println(a);
}
Page
74
}
Output :
Page
75
System.out.println("Maximum "+max);
int min;
if(a>b)
min=a;
else
min=b;
if(min<c)
min=c;
System.out.println("Minimum "+min);
}
}
Output :
Page
76
else
System.out.println(i+" is odd number");
}
}
}
Output :
Page
77
if(age>=18){
if(marks<=70)
System.out.println("Admission allowed");
}
else
System.out.println("Admission not allowed");
}
}
Output :
Page
78
Output :
}
Output :
Page
79
Q.25] Design a menu card and write a program.
Answer:-
Code:
import javax.swing.JOptionPane;
private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {
int price=0;
int a,b,c,d,e;
if(jCheckBox1.isSelected())
a=110;
else
a=0;
if(jCheckBox2.isSelected())
b=150;
else
b=0;
if(jCheckBox3.isSelected())
c=160;
else
c=0;
if(jCheckBox4.isSelected())
d=60;
else
Page
80
d=0;
if(jCheckBox5.isSelected())
e=130;
else
e=0;
int total=a+b+c+d+e;
jTextField1.setText(“ ”);
}
import javax.swing.JOptionPane;
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {
JOptionPane.showMessageDialog(this,"REcord
updated payment successful");
}
Design & output :-
Page
81
import java.util.Scanner;
public class calculate {
public static void main(String args[]){
int num;
System.out.println("Enter an integer number :\
n");
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
System.out.println("Square of "+num+" is
"+Math.pow(num,2));
System.out.println("Cube of "+num+" is
"+Math.pow(num,3));
}
}
Output:
Page
82
long
MobileNo=Long.parseLong(jTextField3.getText());
String bloodGroup=jTextField4.getText();
jTextArea1.setText("Full Name :"+fullName+"\n
Address :"+address+"\n Mobile No.:"+MobileNo+"\n
Blood Group"+bloodGroup);
}
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {
jTextField1.setText(" ");
jTextField2.setText(" ");
jTextField3.setText(" ");
jTextField4.setText(" ");
}
private void
jButton3ActionPerformed(java.awt.event.ActionEve
nt evt) {
System.exit(0);
}
Design & output:
Page
83
Q.28]Calculate the temperature of the following cities:
Latur , Solapur ,Mumbai , Pune , Ratnagiri and Lonavala.
Answer:-
Code:
private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {
String s=(String)CityList.getSelectedItem();
jTextField1.setText(s);
int i=CityList.getSelectedIndex();
switch(i)
{
case 0:jTextField2.setText("15 Degree
Celcius");
break;
case 1:jTextField2.setText("28 Degree
Celcius");
break;
case 2:jTextField2.setText("29 Degree
Celcius");
break;
Page
84
case 3:jTextField2.setText("27 Degree
Celcius");
break;
case 4:jTextField2.setText("31 Degree
Celcius");
break;
case 5:jTextField2.setText("31 Degree
Celcius");
break;
default:jTextField2.setText("0");
}
Page
85
String r=jTextField1.getText();
float radius=Float.parseFloat(r);
float area=3.14f*radius*radius;
JOptionPane.showMessageDialog(this,"Area of
circle is "+area);
import javax.swing.JOptionPane;
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {
String r=jTextField1.getText();
float radius=Float.parseFloat(r);
float perimeter=2*3.14f*radius;
JOptionPane.showMessageDialog(this,"Perimeter of
circle is "+perimeter);
}
Design & output:
Page
86
Code:
import javax.swing.JOptionPane;
private void
jButton1ActionPerformed(java.awt.event.ActionEve
nt evt) {
String s=jTextField1.getText();
float side=Float.parseFloat(s);
float area=side*side;
JOptionPane.showMessageDialog(this,"Area of
square is "+area);
}
import javax.swing.JOptionPane;
private void
jButton2ActionPerformed(java.awt.event.ActionEve
nt evt) {
String s=jTextField1.getText();
float side=Float.parseFloat(s);
float perimeter=4*side;
JOptionPane.showMessageDialog(this,"Perimeter of
square is "+perimeter);
}
Design & output:
Page
87
Page
88