Question:

(i) Write the SQL statement to create a table, Customer with the following specifications:

(ii) Write the SQL query to display all records in descending order of LName from the Table Customer.
 

Show Hint

Use ORDER BY column ASC for ascending order and ORDER BY column DESC for descending order in SQL.
Updated On: Jul 14, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

(i) SQL statement to create the table:
The following SQL command will create the Customer table as per the given structure.
CREATE TABLE Customer (
    CID INT PRIMARY KEY,
    FName VARCHAR(20),
    LName VARCHAR(20),
    Age INT
);

Explanation:
1. The `CREATE TABLE` command starts the table definition with the name Customer.
2. `CID` is defined as INT and set as PRIMARY KEY, meaning it uniquely identifies each record.
3. `FName` and `LName` are both defined as VARCHAR(20) to store first and last names with a maximum length of 20 characters.
4. `Age` is defined as INT to store numeric age values.
This creates the table with proper columns and sets CID as the primary key for uniqueness.
(ii) SQL query to display records in descending order of LName:
To view all rows from Customer in descending order of last name, use the following SQL statement.
SELECT * FROM Customer
ORDER BY LName DESC;

Explanation:
1. `SELECT *` fetches all columns for each record from the Customer table.
2. `ORDER BY LName` sorts the results by the LName column.
3. `DESC` specifies descending order, so records with later alphabet last names appear first.
This ensures all customer records are displayed from Z to A based on the LName field.
Was this answer helpful?
0
0

Top Questions on SQL Queries

View More Questions