![]() |
In SQL, capitalizing the first letter of a string can be essential for formatting data or presenting it in a standardized way. Whether you’re dealing with names, titles, or any textual data, knowing how to modify the case of letters is a fundamental skill. This guide explores how to capitalize the first letter of a string in SQL, using functions like UPPER(), LOWER(), and SUBSTRING() in MySQL, ensuring your data is presented correctly and professionally. Steps to Capitalize First Letter in SQLStep 1: Create the DatabaseTo begin, let’s create a database named “GEEKSFORGEEKS.” CREATE DATABASE GEEKSFORGEEKS;
Output: After executing the above command, observe the schemas window on the left updated with the “GEEKSFORGEEKS” database. Step 2: Use the DatabaseNext, switch to the “GEEKSFORGEEKS” database for further operations. USE GEEKSFORGEEKS
Output: Now we are using the “GEEKSFORGEEKS” database. Step 3: Create the Student Table Create a table named “student” with columns CREATE TABLE IF NOT EXISTS Student ( Student table: ![]() Output The “student” table is created successfully with Step 4: Insert Rows into the Student TableInsert three rows of data into the “student” table. INSERT INTO Student (std_id, name) VALUES ('1', 'jaNU'); Output: Three rows are inserted into the “Student” table with lowercase names. Step 5: Display All Rows from the Student TableRetrieve and display all rows from the “student” table. SELECT * FROM Student;
Output: +--------+-------+ Step 6: Format Names with First Letter UppercaseRetrieve student names from the “student” table with the first letter capitalized and the rest in lowercase using SQL string functions. Query: SELECT Output: +--------+------------------+ Finally, we can see the names of the student in the student table with the first character being upper and the rest are lower. Transforming First Letter Capitalization in SQL
These functions combined allow for modifying the case of strings effectively within SQL queries. ConclusionIn conclusion, this article demonstrated how to capitalize the first letter of names retrieved from a SQL Server database using SQL string functions. By leveraging functions like Capitalizing the first letter of names is essential for maintaining data consistency and presentation standards in applications and reports. SQL’s robust capabilities make it a powerful tool for data management tasks, providing flexibility and efficiency in handling text manipulation requirements within relational databases. FAQs on How To Capitalize First Letter in SQLWhat SQL functions are used to capitalize the first letter of a string?
Can this method handle names with special characters or numbers?
Are there any limitations to using these functions?
|
Reffered: https://www.geeksforgeeks.org
SQL |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |