SQL Practical Exercises
10 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the primary key in the 'student' table?

  • studid (correct)
  • student_id
  • name
  • marks

Which command would you use to insert a new student into the 'student' table?

  • add into student values(6, 'Anita', 75);
  • insert student(6, 'Anita', 75);
  • insert into student values(6, 'Anita', 75); (correct)
  • insert student values(6, 'Anita', 75);

How would you retrieve students with marks greater than or equal to 80?

  • select * from student where marks > 80;
  • select student from marks >= 80;
  • select * where marks >= 80 from student;
  • select * from student where marks >= 80; (correct)

What is the purpose of the 'group by' clause in SQL?

<p>To aggregate data across multiple rows. (A)</p> Signup and view all the answers

Which SQL command correctly returns the total number of customers grouped by country?

<p>select country, count(cname) as 'Total_Customers' from customer group by country; (C)</p> Signup and view all the answers

How do you sort the student records by name in descending order?

<p>select * from student order by name DESC; (B)</p> Signup and view all the answers

What does the following SQL command do: 'Select UPPER(pname) as ‘patient name’, YEAR(admitdate) as ‘admit year’ From hospital;'?

<p>Displays patient names in uppercase and their admission years. (C)</p> Signup and view all the answers

Which SQL command will correctly fetch the first four letters of patient names admitted before May?

<p>Select LEFT(pname,4), LENGTH(pname) from hospital where month(admitdate) &lt; 5; (B)</p> Signup and view all the answers

What command is used to create a new database in SQL?

<p>create database newDatabase; (B)</p> Signup and view all the answers

Which SQL command will display the names of coaches earning more than 3500 in ascending order of their names?

<p>SELECT coachname from club WHERE pay &gt; 3500 ORDER BY name ASC; (D)</p> Signup and view all the answers

Flashcards

Creating a student table

SQL statement to define a table named 'student' with columns for student ID, name, and marks. Student ID is the primary key.

Inserting student data

SQL statement to add new rows (records) with student information into an existing 'student' table.

Querying students with marks > 80

SQL statement to retrieve details of students who have scored more than 80 marks in the 'student' table.

Counting customers per country

SQL statement to count customer records per distinct country, from a 'customer' table (containing customer ID, name, and country).

Signup and view all the flashcards

Ordering by marks (desc)

SQL statement to sort rows of the 'student' table in descending order based on the marks.

Signup and view all the flashcards

Displaying patient names with admit year

SQL query to display patient names (in upper case) and the year of admission, from the 'Hospital' table.

Signup and view all the flashcards

Displaying first four letters and length

SQL query to display the first four letters of patient names and their name length (who were admitted before May), from the 'Hospital' table.

Signup and view all the flashcards

Creating a database

SQL command to create a new database.

Signup and view all the flashcards

Creating table

SQL statement that creates a table (as described in problem statement), specifying columns and data types.

Signup and view all the flashcards

Insert data into table

SQL command to insert values into a table (rows).

Signup and view all the flashcards

Study Notes

Practical-1

  • Problem: Create a student table with studid (primary key), name, and marks.
  • Solution: SQL code to create the table.

Practical-2

  • Problem: Insert student details into the student table.
  • Solution: SQL insert statements for various students (e.g., Sanjay, Surendra, Jamil, Rahul, Prakash), providing their studid, name, and marks.

Practical-3

  • Problem: Retrieve student details with marks above 80.
  • Solution: SQL query to filter students where marks are greater than or equal to 80.

Practical-5

  • Problem: Calculate the total number of customers from each country.
  • Solution: SQL query to count customers by country.

Practical-6

  • Problem: Order student records (studid, marks) by name in descending order.
  • Solution: SQL query to sort student records by name in descending order.

Practical-7 (Min, Max, Sum, Average)

  • Problem: Find the minimum, maximum, sum, and average of marks.
  • Solution: SQL query using min(), max(), sum(), and avg() functions on the marks column.

Practical-8

  • Problem: Display patient names in uppercase and admission year.
  • Solution: SQL query using UPPER() and YEAR() functions on pname and admitdate attributes, respectively.

Practical-9

  • Problem: Display first four letters of patient names and the name length, for patients admitted before May.
  • Solution: SQL query using LEFT() and LENGTH() functions.

Practical-10 (Creating and Inserting into a Table)

  • Problem: Create a database (e.g., abc) and a table within it. Insert data into the table (e.g., Coach's coachname, age, sports, salary, sex details)
  • Solution: SQL commands to create a database, club table with fields (coach_id, coachname, age, sports, salary, sex). Insert data for various coach records.
  • Additional Problem (Practical-10): Display coaches playing basketball
  • Solution: Select coach names where sports is "Basketball".

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

MySQL Practical File PDF

Description

This quiz covers various practical exercises related to SQL, including creating a student table, inserting records, and retrieving data based on conditions. You'll also learn to perform aggregate functions like counting, finding min/max, and ordering results. Test your SQL skills with hands-on examples and queries.

More Like This

Use Quizgecko on...
Browser
Browser