Fun SQL Pt. 1

Sunday, January 15, 2023 | Permalink

I'd like to meet a woman with varied interests, curious about the world, comfortable expressing her likes and dislikes (I hate struggling to guess), delighting in her ability to fascinate a man and in being loved tenderly, who values joy, truth, beauty and justice more than "success"--so we can share bouts of intense, passionately kind awareness of each other, alternating with tolerant warmth while we're absorbed in other aspects of life.

Richard M. Stallman, My former Personal Ad

Hi! I am Jack and I am nerd. I maintain one irc channel #bmachine where around 200 hackers can talk and share their ideas on machine programming and binary instructions. Nobody except me know all these hackers. So, I decided to make an environment where they know each other and if they like (in case) they can date each others or be a friend (or co-founder of startup if their interests are same). I was thinking about what to do and the I decided to make a cmd-db for them where they can search each other and communicate.

Basically this cmd-db contains basic information about each user and users can find against this basic info. This basic information includes username, first name, last name and interest. But, I don't know anything about database and how to make this cmd-db. So I decided to take help from my friend Joe. He is web developer so I think he know about database.

I met him and talk about this cmd-db environment and he suggest to use SQLite software. Based on my search, I found that SQLite is database management software used by millions of developers and its free. So, I have decided that I will going to use this software to store all information.

In order to follow this post you need to install SQLite. You can download SQLite from Official Website and can use from terminal.

I get one copy of SQLite and install in such a way so that users can access it from specific URL. But, now the main question comes: How can I put all information here and how can other access it? I asked same to Joe:

Hi Joe, I have installed SQLite as per your instruction and make it accessible to all users. But, I don't know how to place the data on it.

You have to create a database in SQLite and then table. Inside of this table you can store your data.

But why?

Because, SQLite is a relational database and it stores all information in form of tables. You can not directly create a table. A table is part of one particular database. So, you first have to create one database and then table and then you have to insert all this information.

Oh! I see. But how?

With the use of SQL language. You need to write query in SQL for each things that you want to do with database. If you need to insert something inside of table you have to write INSERT query, if you need to update something you need to write UPDATE query.

Wait. How many queries are there?

Infinite. But... The fundamentals on which these queries are created is simple, If you know the fundamentals then you can easily work with any databases. I mean with any such as Oracle, MySQL, MS SQL Server.

Oh! That's good news I say...But, things are not done here. I also have to tell users to how they can use this cmd-db.

In that case what you have to do is - publish a little note on how to use cmd-db. I mean it will be the easy for them then you maintaining cmd-db. They just need to write couple of queries in-order to access information.

Okay, I hope this will be easy for them.

Don't worry. It will be easy for them.

Now from where I have to start?

First you need to create one database or db, then one table inside of that newly created db and then you can insert all your information. Basically this information will be stored in format of table, where each row contains information about one particular user and each column contains information about particular entity such as firstname. What information do you want to store?

I want to store - username, first name, last name and interest.

That means four. So you have create one table with four columns. One column for each entity. It will look something like this:

userid username firstname lastname interest
1 uname F Name L Name Hacking
2 uname2 F Name1 L Name1 Coooking

Wait Joe. Why userid here?

To uniquely identify each user over a table. I mean it might possible that two users has same username or first name or last name or interest. So, using something call id will make sure you can identify each user uniquely.

No, each user have unique username.

I know. But, we still need this userid. There are many significant uses of it, which I will tell you later but for now, please use userid.

Okay Joe. I am going home and will do search on how to make database and table. I will call you in case of difficulties.

Sure, Bye.

And then on same day I publish a note on #bmachine:

Hi everybody. I am going to create one database which includes details such as
username, fname, lname and interest of all users of this channel so you can 
better communicate with each other and share thoughts personally (if needed).
Please send your username, fname, lname and interest in personal.  
  
Thanks  
Jack

Labels: