Minggu, 22 Maret 2020

Learn SQL Database : ERD, Basic of SQL Table and Little Example of MySQL Function

    Have you ever wonder, what is database table for? Or have you ever wonder how the customer service like Telkomsel CS, can save people's data?

     First thing first, learn what is usually Customer Service does in the office, especially for telecommunication or networking things. If we understand what they do, then we can continue and design their workflow into an Entity Relation Diagram (ERD) like in this...



      From this ERD, we can now create a database containing each entity. Let's name the database as "customer_service" like this...



     Then after the database, we need tables for the 3 entities in the ERD, which are Customer, Customer Service, and the office. So let's create these 3 tables with the name "customer", "customer_service", and "telkomsel_office" like this...




     Now let's take some samples for the customer and who will be the customer service, then insert those samples to these SQL-Tables. For me, I already sampled some of my friend's data for customer members and myself for the customer service, it looks like this...



     Now these all we need! Now, do you know what is SQL functions? No? Okay, take it easy... I will show you a little bit of it because literally, it's so many. I only remember some of them HAHA. But, if you are curious, pay a visit to this page, it's very useful!

     But for now, let's continue! We want to try some MySQL functions right? First... CONCAT_WS() function. It is used to join two or more Strings or expressions with separators like "-", "&", etc. Second, it will be LCASE() function. Used to lowercase all the capital letters. Third, LENGTH() function. As the name of it, it is used to measures the length of the String. Fourth... UCASE() function. Just like the name of it, it is used to uppercase all the capital letters. And the last is  SUM(). Used as adders for numbers and decimals.

    Okay, now let's try CONCAT_WS first... For example, we want to join the CustomerName and CustomerAddress with a separator " from " like this...


     Now the second function, LCASE() to lowercases the CustomerName, let's try it! It should be like this...


     Third, let's try the LENGTH() function, one of the most powerful functions for me in MySQL. Let's give it a try with my name in CustomerServiceName, It should be something like this...


    It's all easy right? Now for the fourth! UCASE() function... Let's try by uppercasing all the CustomerAddress now!


     Now for the last function, we will use SUM() to add all the CustomerID as Sum_of_ID, wanna try it? Okay, let's do it!



     That's it for the basic of SQL and MySQL functions tutorial, if you have any questions regarding this material, feel free to ask in the comment section below. Thank you :)






Tidak ada komentar:

Posting Komentar