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.</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;</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;</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.</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;</p> Signup and view all the answers

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

    <p>create database newDatabase;</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;</p> Signup and view all the answers

    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