SQL Practical Questions/Answers
Create a new database named “company”.
Answer: CREATE DATABASE company;
Create a table named “employees” with columns for id (integer, primary key), name (varchar), age (integer), and department (varchar).
Answer: CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(255), age INT, department VARCHAR(255));
Create a table named “products” in the “company” database with columns for id (integer, primary key), name (varchar), price (decimal), and quantity (integer).
Answer: CREATE TABLE company.products (id INT PRIMARY KEY, name VARCHAR(255), price DECIMAL(10, 2), quantity INT);
Alter the “employees” table to add a new column named “salary” (integer).
Answer: ALTER TABLE employees ADD COLUMN salary INT;
Alter the “products” table to add a new column named “description” (text).
Answer: ALTER TABLE company.products ADD COLUMN description TEXT;
Alter the “products” table to modify the data type of the “price” column to FLOAT.
Answer: ALTER TABLE company.products MODIFY COLUMN price FLOAT;
Alter the “products” table to rename the column “quantity” to “stock”.
Answer: ALTER TABLE company.products RENAME COLUMN quantity TO stock;
Drop the “salary” column from the “employees” table.
Answer: ALTER TABLE employees DROP COLUMN salary;
Insert a new record into the “products” table in the “company” database with values for id, name, price, and stock.
Answer: INSERT INTO company.products (id, name, price, stock) VALUES (1, 'Laptop', 999.99, 50);
Insert multiple records into the “products” table in the “company” database with values for id, name, price, and stock.
Answer: INSERT INTO company.products (id, name, price, stock) VALUES (2, 'Smartphone', 499.99, 100), (3, 'Tablet', 299.99, 75), (4, 'Headphones', 99.99, 200);
Insert a new record into the “employees” table with values for id, name, age, and department.
Answer: INSERT INTO employees (id, name, age, department) VALUES (1, 'John', 35, 'HR');
Insert a new record into the “employees” table with values for id, name, age, department, and salary.
Answer: INSERT INTO employees (id, name, age, department, salary) VALUES (4, 'Alice', 28, 'Marketing', 50000);
Update the price of the product with id 2 to 549.99 in the “products” table.
Answer: UPDATE company.products SET price = 549.99 WHERE id = 2;
Update the stock of the product with id 1 to 40 and its price to 899.99 in the “products” table.
Answer: UPDATE company.products SET stock = 40, price = 899.99 WHERE id = 1;
Update the age of the employee with id 1 to 30 in the “employees” table.
Answer: UPDATE employees SET age = 30 WHERE id = 1;
Update the department of the employee with id 2 to ‘Finance’ in the “employees” table.
Answer: UPDATE employees SET department = 'Finance' WHERE id = 2;
Delete the record with id 3 from the “products” table in the “company” database.
Answer: DELETE FROM company.products WHERE id = 3;
Delete all records from the “products” table where the price is less than 100.
Answer: DELETE FROM company.products WHERE price < 100;
Delete all records from the “products” table.
Answer: DELETE FROM company.products;
Delete all records from the “employees” table where the age is greater than 50.
Answer: DELETE FROM employees WHERE age > 50;
Delete the employee with id 3 from the “employees” table.
Answer: DELETE FROM employees WHERE id = 3;
Select all columns from the “employees” table.
Answer: SELECT * FROM employees;
Select only the “name” and “age” columns from the “employees” table.
Answer: SELECT name, age FROM employees;
Select all employees from the “employees” table where the department is ‘IT’.
Answer: SELECT * FROM employees WHERE department = 'IT';
Select all employees from the “employees” table where the age is between 25 and 35.
Answer: SELECT * FROM employees WHERE age BETWEEN 25 AND 35;
Select all employees from the “employees” table sorted by age in ascending order.
Answer: SELECT * FROM employees ORDER BY age ASC;
Select the oldest employee from the “employees” table.
Answer: SELECT * FROM employees ORDER BY age DESC LIMIT 1;
Retrieve unique values from the “department” column in the “employees” table.
Answer: SELECT DISTINCT department FROM employees;
Retrieve the first 10 records from the “orders” table, ordered by the “order_date” column in descending order.
Answer: SELECT * FROM orders ORDER BY order_date DESC LIMIT 10;
Find the total number of records in the “products” table.
Answer: SELECT COUNT(*) FROM products;
Update the “price” column of the “products” table to 50 where the “category” is ‘Electronics’.
Answer: UPDATE products SET price = 50 WHERE category = 'Electronics';
Delete all records from the “employees” table where the “department” is ‘HR’.
Answer: DELETE FROM employees WHERE department = 'HR';
Retrieve the average salary of employees from the “employees” table.
Answer: SELECT AVG(salary) FROM employees;
Find the highest salary from the “employees” table.
Answer: SELECT MAX(salary) FROM employees;
Retrieve the names of employees who have joined after ‘2020-01-01’.
Answer: SELECT name FROM employees WHERE join_date > '2020-01-01';
Retrieve the second highest salary from the “employees” table.
Answer: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees);
Calculate the total sales amount for each product from the “sales” table and group them by product ID.
Answer: SELECT product_id, SUM(amount) AS total_sales FROM sales GROUP BY product_id;
Retrieve all orders where the order amount is greater than $1000 from the “orders” table.
Answer: SELECT * FROM orders WHERE order_amount > 1000;
Find the number of orders placed by each customer from the “orders” table and group them by customer ID.
Answer: SELECT customer_id, COUNT(order_id) AS order_count FROM orders GROUP BY customer_id;
Find the top 5 best-selling products from the “products” table based on the quantity sold.
Answer: SELECT product_id, SUM(quantity_sold) AS total_quantity FROM products GROUP BY product_id ORDER BY total_quantity DESC LIMIT 5;
Retrieve all columns from the “employees” table where the salary is greater than $50000.
Answer: SELECT * FROM employees WHERE salary > 50000;
Find the total number of customers from the “customers” table.
Answer: SELECT COUNT(*) FROM customers;
Retrieve the names and ages of customers from the “customers” table who are older than 30 years.
Answer: SELECT name, age FROM customers WHERE age > 30;
Update the “status” column of the “orders” table to ‘Completed’ where the “order_date” is before ‘2023-01-01’.
Answer: UPDATE orders SET status = 'Completed' WHERE order_date < '2023-01-01';
Delete all records from the “products” table where the “category” is ‘Books’.
Answer: DELETE FROM products WHERE category = 'Books';
Retrieve the names and email addresses of customers from the “customers” table where the email address contains ‘@gmail.com’.
Answer: SELECT name, email FROM customers WHERE email LIKE '%@gmail.com%';
Find the average salary of employees in the “sales” department from the “employees” table.
Answer: SELECT AVG(salary) FROM employees WHERE department = 'Sales';
JavaScript Practical Questions
- Write a JavaScript function to add two numbers.
- Create a function to subtract two numbers.
- Write a function to multiply two numbers.
- Create a function to divide two numbers.
- Write a JavaScript function to find the square of a number.
- Create a function to find the cube of a number.
- Write a JavaScript function to find the maximum of two numbers.
- Create a function to find the minimum of two numbers.
- Write a function to check if a number is positive, negative, or zero.
- Create a JavaScript function to check if a number is even or odd.
- Write a function to check if a number is a multiple of another number.
- Create a JavaScript function to check if a year is a leap year.
- Write a function to calculate the area of a rectangle given its length and width.
- Create a function to calculate the perimeter of a rectangle given its length and width.
- Write a JavaScript function to calculate the area of a circle given its radius.
- Create a function to calculate the circumference of a circle given its radius.
- Write a function to convert Celsius to Fahrenheit.
- Create a JavaScript function to convert Fahrenheit to Celsius.
- Write a function to generate a random integer between two specified values.
- Create a function to generate a random number between 0 and 1.
- Write a JavaScript function to generate an array of specified lengths filled with random integers.
- Create a function to find the factorial of a given number.
- Write a JavaScript function to check if a given number is prime.
- Create a function to find the sum of all numbers in an array.
- Write a function to find the average of numbers in an array.
- Create a JavaScript function to find the largest element in an array.
- Write a function to find the smallest element in an array.
- Create a function to find the median of numbers in an array.
- Write a JavaScript function to reverse a string.
- Create a function to check if a given string is a palindrome.
- Write a function to count the number of vowels in a string.
- Create a JavaScript function to count the number of words in a sentence.
- Write a function to find the longest word in a sentence.
- Create a function to remove duplicates from an array.
- Write a JavaScript function to sort an array of numbers in ascending order.
- Create a function to shuffle elements in an array.
- Write a function to truncate a string to a specified length.
- Create a JavaScript function to capitalize the first letter of each word in a sentence.
- Write a function to find the difference between two dates in days.
- Create a function to check if two arrays are equal.
- Write a JavaScript function to find the intersection of two arrays.
- Create a function to merge two sorted arrays into one sorted array.
- Write a function to remove a specific element from an array.
- Create a JavaScript function to remove all false values from an array.
- Write a function to find the most frequent element in an array.
- Create a function to check if an array contains a specific value.
- Write a JavaScript function to flatten a nested array.
- Create a function to rotate elements in an array to the left by a given number of positions.
- Write a function to generate a Fibonacci sequence up to a specified number of terms.
- Create a JavaScript function to check if a string contains unique characters.\
C Programming Practical Questions
- Write a C program to find the sum of two numbers using a function.
- Create a program to calculate the factorial of a number using a function.
- Write a C program to check if a number is prime using a function.
- Create a program to find the maximum of two numbers using a function.
- Write a C program to reverse a string using a function.
- Create a program to swap two numbers using call by reference.
- Write a C program to sort an array of integers using functions.
- Create a program to find the length of a string using a function.
- Write a C program to concatenate two strings using functions.
- Create a program to find the square of a number using a function.
- Write a C program to implement a structure representing a student with fields for name, roll number, and marks in three subjects.
- Create a program to calculate the average marks of a student using a structure.
- Write a C program to display details of students stored in an array of structures.
- Create a program to find the student with the highest marks using structures.
- Write a C program to implement a union representing the details of an employee with fields for employee ID, name, and salary.
- Create a program to display details of employees stored in an array of unions.
- Write a C program to find the employee with the highest salary using unions.
- Create a program to swap two numbers using pointers.
- Write a C program to reverse an array using pointers.
- Create a program to find the sum of elements in an array using pointers.
- Write a C program to find the length of a string using pointers.
- Create a program to concatenate two strings using pointers.
- Write a C program to implement a linked list to store integers.
- Create a program to insert a node at the beginning of a linked list.
- Write a C program to insert a node at the end of a linked list.
- Create a program to delete a node from a linked list.
- Write a C program to search for a node in a linked list.
- Create a program to reverse a linked list.
- Write a C program to implement a stack using an array.
- Create a program to push an element into a stack.
- Write a C program to pop an element from a stack.
- Create a program to implement a queue using an array.
- Write a C program to enqueue an element into a queue.
- Create a program to dequeue an element from a queue.
- Write a C program to implement a stack using linked list.
- Create a program to push an element into a stack implemented using linked list.
- Write a C program to pop an element from a stack implemented using linked list.
- Create a program to implement a queue using linked list.
- Write a C program to enqueue an element into a queue implemented using linked list.
- Create a program to dequeue an element from a queue implemented using linked list.
- Write a C program to copy contents of one file to another.
- Create a program to count the number of characters, words, and lines in a file.
- Write a C program to find the largest word in a file.
- Create a program to append text to a file.
- Write a C program to merge two files into a third file.
- Create a program to sort lines of text in a file alphabetically.
- Write a C program to encrypt and decrypt text in a file.
- Create a program to find and replace a word in a file.
- Write a C program to search for a specific line in a file.
- Create a program to display the contents of a file in reverse order.
PHP Practical Questions
- Write a PHP script that connects to a MySQL database and inserts user input from a form into a database table.
- Create a PHP script that retrieves user input from a form using the POST method, performs a calculation, and displays the result.
- Write a PHP script that retrieves user input from a form using the GET method, performs a database query based on the input, and displays the results.
- Create a PHP script that connects to a MySQL database, retrieves user input from a form, updates a specific record in the database based on the input, and displays a success message.
- Write a PHP script that connects to a MySQL database, retrieves user input from a form using both POST and GET methods, performs a calculation based on the input, and displays the result.
- Create a PHP script that retrieves user input from a form, validates the input, performs a database query to check if the input exists in the database, and displays appropriate messages.
- Write a PHP script that connects to a MySQL database, retrieves user input from a form using the POST method, inserts the input into multiple database tables, and displays a success message.
- Create a PHP script that retrieves user input from a form using the GET method, performs a database query to fetch relevant data based on the input, and displays the data in a formatted manner.
- Write a PHP script that connects to a MySQL database, retrieves user input from a form using the POST method, performs a calculation based on the input, and updates the result in the database.
- Create a PHP script that retrieves user input from a form using the GET method, performs a database query to fetch relevant data based on the input, calculates the total based on the retrieved data, and displays the total to the user.