0% found this document useful (0 votes)
2 views16 pages

SQL and JAVA Practical

The document contains a series of SQL queries for creating and manipulating a database named 'CaesarTwe2025', including creating tables for 'Department' and 'Employee', modifying table structures, inserting data, and querying information. Additionally, it provides Java programs for basic operations such as printing messages, calculating sums, checking numbers, and finding prime numbers. Each SQL and Java program is presented with the corresponding code and expected output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views16 pages

SQL and JAVA Practical

The document contains a series of SQL queries for creating and manipulating a database named 'CaesarTwe2025', including creating tables for 'Department' and 'Employee', modifying table structures, inserting data, and querying information. Additionally, it provides Java programs for basic operations such as printing messages, calculating sums, checking numbers, and finding prime numbers. Each SQL and Java program is presented with the corresponding code and expected output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

WRITE THE FOLLOWING SQL QUERIES

1. Create a Database named ‘CaesarTwe2025’.


Ans: CREATE DATABASE CaesarTwe2025;

2. Use the Database CaesarTwe2025.


Ans: USE CaesarTwe2025;

3. Create the table ‘Department’ with given datatype and constraints:-


Did: INTEGER, PRIMARY KEY
Dname: VARCHAR(80)

Ans: CREATE TABLE Department(Did INTEGER PRIMARY KEY, Dname VARCHAR(80));

4. Change the datatype of column Dname from VARCHAR(80) to VARCHAR(100) and the
column should not contain any NULL value in the table Department.
Ans: ALTER TABLE Department MODIFY Dname VARCHAR(100) NOT NULL;

5. Show the structure of the table Department.


Ans: DESCRIBE Department;
Field Type Null Key Default Extra
Did int(11) NO PRI NULL
Dname varchar(100) NO NULL

6. Insert the following values in the given rows in the table Department:-
Row 1: 101, ‘English’
Row 2: 102, ‘Accounts’
Row 3: 103, ‘History’
Row 4: 104, ‘Information Technology’

Ans: INSERT INTO Department(Did, Dname) VALUES(101, ‘English’);


INSERT INTO Department(Did, Dname) VALUES(102, ‘Accounts’);
INSERT INTO Department(Did, Dname) VALUES(103, ‘History’);
INSERT INTO Department(Did, Dname) VALUES(104, ‘Information Technology’);
7. Create the table ‘Employee’ with given datatype and constraints:-
Empid: INTEGER
Empname: VARCHAR(100)
Empaddr: VARCHAR(200)
Empcont: VARCHAR(10), UNIQUE
Edpt: INTEGER, NOT NULL

Ans: CREATE TABLE Employee( EmpId INTEGER, Empname VARCHAR(100), Empaddr


VARCHAR(200), Empcont VARCHAR(10), Edpt INTEGER NOT NULL, UNIQUE(Empcont));

8. Make Empid and Empname PRIMARY KEY of the table Employee.


Ans: ALTER TABLE Employee ADD PRIMARY KEY(Empid, Empname);

9. Insert a column Esal with datatype INTEGER in the table Employee


Ans: ALTER TABLE Employee ADD Empsal INTEGER;

10. Make the default address ‘Malbazar’ for all employees in Employee table.
Ans: ALTER TABLE Employee ALTER Empaddr SET DEFAULT ‘Bus-Stand, Malbazar’;

11. Make Empdid of Employee Foreign Key referencing values of Did of table Department
where Empdid should show changed values if values on Did is changed.
Ans: ALTER TABLE Employee ADD FOREIGN KEY(Empdept) REFERENCES Department(Did) ON
UPDATE CASCADE;

12. Show the structure of the table Employee.


Ans: DESCRIBE Employee;
Field Type Null Key Default Extra
Empid int(11) NO PRI
Empname varchar(100) NO PRI
Empaddr varchar(200) YES Bus-Stand, Malbazar
Empcont varchar(10) YES UNI
Edpt int(11) NO
Esal int(11) YES
13. Insert the following values in the given rows in the table Employee:-
Row 1: 1011, ‘Akshay Jha’, ‘NJP main road, ward-32, Siliguri’, ‘9832512546’, 101, 35000
Row 2: 1012, ‘Akshay Oraon’, ‘Bidhan road, ward-15, Jalpaiguri’, ‘9832016622’, 101, 20000
Row 3: 1013, ‘Dipak Patel, ‘Anandapally, ward-02, Malbazar’, ‘7270123431’, 104, 35000
Row 4: 1014, ‘Kajal Khatun’, ‘Caltex More, ward-10, Malbazar’, ‘6290876543’, 103, 15000
Row 5: 1015, ‘Bishakha Saha’, ‘+91-9563212345’, 104, 15000
Row 6: 1016, ‘Ananya Sarkar’, ‘Anandapally, ward-02, Malbazar’, 102, 35000
Row 7: 1017, ‘Kamal Sah’, ‘Dabgram, ward-22, Siliguri’, ‘9677854309’, 102, 20000
Row 8: 1018, ‘Zubair Hussain’, ‘Ukilpara, ward-25, Jalpaiguri’, ‘7004567890’, 103, 35000

Ans: INSERT INTO Employee VALUES(1011, ‘Akshay Jha’, ‘NJP main road, ward-32, Siliguri’,
‘9832512546’, 101, 35000);
INSERT INTO Employee VALUES(1012, ‘Akshay Oraon’, ‘Bidhan road, ward-15,
Jalpaiguri’, ‘9832016622’, 101, 20000);
INSERT INTO Employee VALUES(1013, ‘Dipak Patel, ‘Anandapally, ward-02, Malbazar’,
‘7270123431’, 104, 35000);
INSERT INTO Employee VALUES(1014, ‘Kajal Khatun’, ‘Caltex More, ward-10, Malbazar’,
‘6290876543’, 103, 15000);
INSERT INTO Employee(Empid, Empname, Empcont, Edpt, Esal) VALUES(1015,
‘Bishakha Saha’, ‘9563212345’, 104, 15000);
INSERT INTO Employee(Empid, Empname, Empaddr, Edpt, Esal) VALUES(1016, ‘Ananya
Sarkar’, ‘Anandapally, ward-02, Malbazar’, 102, 35000);
INSERT INTO Employee VALUES(1017, ‘Kamal Sah’, ‘Dabgram, ward-22, Siliguri’,
‘9677854309’, 102, 20000);
INSERT INTO Employee VALUES(1018, ‘Zubair Hussain’, ‘Ukilpara, ward-25, Jalpaiguri’,
‘7004567890, 103, 35000);

14. Show details of Department table.


Ans: SELECT * FROM Department;
Did Dname
101 English
102 Accounts
103 History
104 Information Technology
15. Show details of all employees from Employee table.
Ans: SELECT * FROM Employee;
Empid Empname Empaddr Empcont Edpt Esal
1011 Akshay Jha NJP main road, ward-32, Siliguri 9832512546 101 35000
1012 Akshay Oraon Bidhan road, ward-15, Jalpaiguri 9832016622 101 20000
1013 Dipak Patel Anandapally, ward-02, Malbazar 7270123431 104 35000
1014 Kajal Khatun Caltex More, ward-10, Malbazar 6290876543 103 15000
1015 Bishakha Saha Bus-Stand, Malbazar 9563212345 104 15000
1016 Ananya Sarkar Anandapally, ward-02, Malbazar 102 35000
1017 Kamal Sah Dabgram, ward-22, Siliguri’ 9677854309 102 20000
1018 Zuabir Hussain Ukilpara, ward-25, Jalpaiguri’ 7004567890 103 35000

16. Show Id, name and address of the employees.


Ans: SELECT Empid, Empname, Empaddr FROM Employee;
Empid Empname Empaddr
1011 Akshay Jha NJP main road, ward-32, Siliguri
1012 Akshay Oraon Bidhan road, ward-15, Jalpaiguri
1013 Dipak Patel Anandapally, ward-02, Malbazar
1014 Kajal Khatun Caltex More, ward-10, Malbazar
1015 Bishakha Saha Bus-Stand, Malbazar
1016 Ananya Sarkar Anandapally, ward-02, Malbazar
1017 Kamal Sah Dabgram, ward-22, Siliguri
1018 Zuabir Hussain Ukilpara, ward-25, Jalpaiguri

17. Show Id and name of employees whose name start with A;


Ans: SELECT Empid, Empname FROM Employee WHERE Empname LIKE ‘A%’;
Empid Empname
1011 Akshay Jha
1012 Akshay Oraon
1016 Ananya Sarkar

18. Show Names and Salary of employees whose Salary is 20000 or more.
Ans: SELECT Empname, Esal FROM Employee WHERE Esal>=20000;
Empname Esal
Akshay Jha 35000
Akshay Oraon 20000
Dipak Patel 35000
Ananya Sarkar 35000
Kamal Sah 20000
Zuabir Hussain 35000
19. Enter Contact as ‘7001525009’ for Ananya Sarkar.
Ans: UPDATE Employee SET Empcont=’ ‘7001525009’ WHERE Empname=’Ananya Sarkar’;
20. Show Id, Name and Bonus of employees which is 10% of their Salary.
Ans: SELECT Empid, Empname, Esal*0.1 AS Bonus FROM Employee;
Empid Empname Bonus
1011 Akshay Jha 3500
1012 Akshay Oraon 2000
1013 Dipak Patel 3500
1014 Kajal Khatun 1500
1015 Bishakha Saha 1500
1016 Ananya Sarkar 3500
1017 Kamal Sah 2000
1018 Zuabir Hussain 3500

WRITE THE FOLLOWING JAVA PROGRAMS


** MAKE SURE THERE’S NO SPELLING MISTAKE OR ANY UNWANTED GAP OR ANNOTATION.
ALSO MAKE SURE TO WRITE WITH PROPER ANNOTATIONS AND PUNCTUATIONS.**
1. Write a Java Program to Print Hello
Ans:
import java.util.*;
class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello");
}
}

2. Write a Java Program to Print the sum of 2 numbers.


Ans:
import java.util.*;
class Sum
{
public static void main(String[] args)
{
int a=5, b=7, s;
s=a+b;
System.out.println(“Sum= "+s);
}
}
3. Write a Java Program to insert 2 numbers and find their product.
Ans:
import java.util.*;
class Prod
{
public static void main(String[] args)
{
int a, b, m;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter numbers”);
a= sc.nextInt();
b= sc.nextInt();
m=a*b;
System.out.println(“Product= "+m);
}
}

4. Write a Java Program to insert a numbers and print the last digit.
Ans:
import java.util.*;
class LastDigit
{
public static void main(String[] args)
{
int a, b;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter number”);
a= sc.nextInt();
b= a%10;
System.out.println(“Last digit = ”+b);
}
}
5. Write a Java Program to insert 2 numbers and find the bigger number
Ans:
import java.util.*;
class Big
{
public static void main(String[] args)
{
int a, b;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter number”);
a= sc.nextInt();
b= sc.nextInt();
if(a>b)
{
System.out.println(“Bigger number= “+a);
}
else
{
System.out.println(“Bigger number= “+b);
}
}
}
6. Write a Java Program to insert a number and check if it is a positive or negative number or
not.
Ans:
import java.util.*;
class PosNeg
{
public static void main(String[] args)
{
int a;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter number”);
a= sc.nextInt();
if(a>0)
{
System.out.println(“positive number”);
}
else
{
System.out.println(“negative number“);
}
}
}
7. Write a Java Program to insert a number and check if it is an even number or odd.
Ans:
import java.util.*;
class OddEven
{
public static void main(String[] args)
{
int a;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter number”);
a= sc.nextInt();
if(a%2==0)
{
System.out.println(“Even number“);
}
else
{
System.out.println(“Odd number”);
}
}
}
8. Write a Java Program to insert 3 random numbers and find the largest number.
Ans:
import java.util.*;
class Largest
{
public static void main(String[] args)
{
int a, b;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter numbers”);
a= sc.nextInt();
b= sc.nextInt();
if(a>b&&a>c)
{
System.out.println(“largest number= “+a);
}
else if(b>a&&b>c)
{
System.out.println(“largest number= “+b);
}
else
{
System.out.println(“largest number= “+c);
}
}
}
9. Write a Java Program to print “Hello” 5 times using while loop.
Ans:
import java.util.*;
class Hello
{
public static void main(String[] args)
{
int i=1;
while(i<=5)
{
System.out.println(“Hello”);
i++;
}
}
}
10. Write a Java Program to print the 1st 100 Natural numbers.
Ans:
import java.util.*;
class Natural
{
public static void main(String[] args)
{
int i=1;
while(i<=100)
{
System.out.println(i);
i++;
}
}
}

11. Write a Java Profram to Print the sum and average of the 1st 100 Natural numbers.
Ans:
import java.util.*;
class SumAvg
{
public static void main(String[] args)
{
int i=1, s=0, avg;
while(i<=5)
{
s=s+i;
i++;
}
i- - ;
avg=sum/i;
System.out.println(“Sum of 1st 100 Nutural nos. =”+s);
System.out.println(“Average of 1st 100 Nutural nos. =”+avg);
}
}
12. Write a Java Program to insert 5 numbers and Print their sum.
Ans:
import java.util.*;
class Sum
{
public static void main(String[] args)
{
int i=1, n, s=0;
Scanner sc= newScanner(System.in);
while(i<=5)
{
System.out.println(“Enter number”);
n= sc.nextInt();
s=s+n;
i++;
}
System.out.println(“Sum of 5 nos. =”+s);
}
}

13. Write a Java Program to find the even and odd numbers between 1 and 100.
Ans:
import java.util.*;
class EvenOdd2
{
public static void main(String[] args)
{
for(i=1;i<=100;i++)
{
if(i%2==0)
{
System.out.println(“Even no “+i);
}
else
{
System.out.println(“odd no “+i);
}
}
}
}
14. Write a Java program to check if a number is prime or not.
Ans:
import java.util.*;
class Prime
{
public static void main(String[] args)
{
int i, n, c=0;
Scanner sc= new Scanner(System.in);
System.out.println(“Enter number ”);
n= sc.nextInt();
for(i=2;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==0)
{
System.out.println(n+" is a prime number");
}
else
{
System.out.println(n+" is not a prime number");
}
}
}
15. Write a Java Program to Sort the elements of an array using Bubble Sort.
Ans:
import java.util.*;
class Test2
{
public static void main(String[] args)
{
int i, j, temp, n;
Scanner sc= new Scanner(System.in);
System.out.println("Enter array limit");
n= sc.nextInt();
int a[]= new int[n];
System.out.println("Enter array elements");
for(i=0; i<n; i++)
{
a[i]=sc.nextInt();
}
for (i=0; i< n; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[j] < a[i])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("After sorting elements are");
for(i=0; i<n; i++)
{
System.out.println(a[i]);
}
}
}
16. Write a Java Program to print the id, roll number, name, class of 3 students using
Parameterized constructor.
Ans:
import java.util.*;
class Student
{
int id, roll;
String name;
String cls;
Student(int i, int r, String n, String c)
{
id= i;
roll= r
name= n;
cls= c;
}
void display()
{
System.out.println(id+” ”+roll+” ”+name+” ”+cls);
}
public static void main(String[] args)
{
Student s1 = new Student(101, 32, "John", “XII-HUM”);
Student s2 = new Student(102, 42, "Jason", “XII-HUM”);
Student s3 = new Student(103, 22, "June", “XII-COM”);
s1.display();
s2.display();
s3.display();
}
}
17. Write a Java Program to show Multilevel Inheritence.
Ans:
import java.util.*;
class GrandFather
{
public void house()
{
System.out.println("3 BHK House.");
}
}
class Father extends GrandFather
{
public void land()
{
System.out.println("5 Arcs of Land..");
}
}
class Son extends Father
{
public void car()
{
System.out.println("Own Audi Car..");
}
}
public class multilevel
{
public static void main(String args[])
{
Son ob = new Son();
ob.car();
ob.house();
ob.land();
}
}

You might also like