Skip to content

Get the most out of MSSQL !

Consultant & Trainer for all things MSSQL

  • Home
  • Company
  • Business Intelligence
  • Simply Better Business

Learning SQL – The column

Posted on April 2, 2014March 20, 2021 by jayanth.kurup

In this blog I am trying to put the things together a very basic level tutorial on understanding databases and more specifically how to implement one in MS SQL. Since the purpose of any database is to store data lets first look at the data itself. Say for example my name “Jayanth Kurup”. This is a piece of information I want to have saved somewhere on a computer so that I can access it at will; either directly or via website or some other piece of software like MS Excel etc.

Let’s look more closely at the data we have here. Jayanth Kurup is obviously a name but we need to now store it in a database before we do that we need to understand what kind of name it is. Is it a Full Name, Nick Name, User Name, Product Name, Preferred name etc. In this case it’s my Full Name. I would define this piece of information as

Full Name = Jayanth Kurup

It becomes pretty obvious that the data is the full Name for a person called Jayanth Kurup. Now we need to set some rules around what properties a Full name has. E.g a full Name will almost always contain only alphabets. However there may be a case for numbers to be listed here as well say Mark 1. So let’s assume for now that both alphabets and numbers are allowed. We can agree that a name will usually not exceed 64 characters in most countries and even if it does that’s usually an edge case. A key thing to remember is that we can’t account for every possible scenario and therefore need to leave a little space for flexibility but at the same time we can’t leave things open ended as that will allow all kinds of bad data to creep in. At this point we need to understand that not everybody has names that are the same length so it makes sense for us to store the data in a fashion such that it occupies just enough space to store the information.

Full Name = Jayanth Kurup (Accepted values = Alpha numeric, variable character length between 0 and 64)

The next point we need to address is: should we ever allow a scenario where a Full Name can be blank. i.e. Full Name = Nothing.

It might not seem like a big deal but it’s important to understand that certain types of data must always have a value assigned with it. For example an address will always have a zip code associated with it. Similarly everybody has a name so it’s unlikely we will ever have a scenario where the Full Name is NULL (NULL = nothing in database parlance).

Full Name = Jayanth Kurup (Accepted values = Alpha numeric, variable character length=1- 64, cannot be empty)

Naturally the next question we have to address is what language the data is stored in. e.g. my Name can be written in English as shown above or even in Hindi. So we need to define the language that this piece of information uses, in this case English.

Full Name = Jayanth Kurup (Accepted values = Alpha numeric, variable character length=1- 64, cannot be empty, Locale = English)

Its looks like we have some basic guidelines about what the information should look like before it can be assigned to the group call Full Name. However there is one more important area we need to address. In what context is this full Name being used? For example is this the full name of people in my address book, or the full name stored in an online website for their customer’s registration page. In the former it might make more sense for me to call it Contact Full Name and in the later it makes more sense to call it Customer Full Name. Other examples could be employee full name etc. Let’s assume this is a contacts database for now.

Contacts Full Name = Jayanth Kurup (Accepted values = Alpha numeric, variable character length=1- 64, cannot be empty, Locale = English)

Now it’s times to store this information in a database. Before we do this let’s look at how we would store this data in a MS Excel spread sheet.

We would naturally add a column called Contacts Full Name and then just below it enter the Value Jayanth Kurup. As shown below

Let’s make some comparisons between Excel and a database now.

MS Excel ~ MS SQL Server ~ Software that stores data

MS Excel Workbook ~ MS SQL Server Database ~ a container in which data related to a specific activity is stored e.g. contacts database, customer database.

MS Excel Workbook Spreadsheet ~ MS SQL Server Database Table ~ a container within the database that stores data of a very specific nature (an object here can mean a person, an address, a product catalogue etc.)

With this understanding you will see that storing data in a database is similar to storing data in a excel sheet. Please keep in mind the traditional database is far more powerful than Excel and implements a lot of check and balances to ensure to integrity and programmability of the data. Inserting a row into the excel sheet has many parallels with how you would insert a row in the database table. You would first need a workbook that you can access. Within the workbook you would access a specific sheet based on the type of data your storing e.g. you wouldn’t store the contact information such as email id in a sheet called hobbies.

With these basics in place let’s create our first database example, before we actually open up SQL Server and start creating the database and tables lets write down the scripts:

Create database ContactsDB     — This statement creates a database in MS SQL Server

GO — This statement tells SQL Server to move on to the next statement

Create Table     Contacts — This line is the starting line for the create table command. Unlike Excel where you can create the sheet first and define columns later, in SQL you need to do both together

( ContactsFullName Varchar (64) NOT NULL ) — The definition of the column which is equal to (Accepted values = Alpha numeric, variable character length=1- 64, cannot be empty, Locale = English)

GO

The above scripts will create a database and a table with the column ContactsFullName. In the next post we explore how to connect to MS SQL Server and execute the above code.

The code in Green needs to be executed together.

Please Consider Subscribing

Subscribe

CategoriesDatabases, UncategorizedTagsability, accepted value, access, account, activity, address, administration, age, AI, alpha numeric, alphabet, Analysis, Analysis Services, area, AWS, Azure, Bangalore, Base Table, basic, Bengaluru, big deal, BigData, BLR, book, Business Intelligence, CaL, call, case, Catalog, CHAR, character, check, Cloud, column, command, comparison, computer, Consultant, Consulting, contact, contact information, contacts database, Contacts Full Name, container, context, Corporate, count, CREATE, Create Table, CTE, customer, Data, database, database table, definition, development, E.g, edge, email, email id, employee, Enabled Business Solutions, enabledbusiness, end, English, etc., example, Excel, exe, exec, EXECUTE, expert, fashion, fine, flexibility, form, format, Full Name, group, Hindi, index, India, info, information, insert, int, Integration, integrity, Jayanth, Jayanth Kurup, key, key thing, kind, Kurup, language, lease, level, line, lot, mail, Mark, mean, member, Migration, min, mind, ML, move, MS Excel, MS SQL, ms sql server, MSBI, MSSQL, MYSQL, name, nature, need, network, NIC, NULL, number, object, ONLINE, Oracle, people, person, piece, place, png, point, post, power, power pivot, Power Query, PowerApps, PowerBI, Powershell, pre, product, product catalogue, Product Name, purpose, Python, question, RAM, RDBMS, red, Remote, Reporting, row, rule, scenario, script, security, sense, server, set, sheet, show, sign, site, software, space, sql, SQL 2000, SQL 2005, SQL 2008, sql 2008 r2, sql 2012, SQL 2014, SQL 2016, SQL 2017, SQl 2019, sql server, SSAS, SSIS, SSMS, SSRS, star, start, starting, state, statement, stores data, storing data, SUM, T-SQL, tab, Tables, text, thing, tie, tools, traditional database, trainer, Transact, tuning, tutor, type, understanding, unl, Upgrade, uploads, user, User Name, USER_NAME, value, VALUES, varchar, variable, variable character length, Very large database, Virtual, virtual machine, visual studio, VM, war, Web, website, windows, work, workbook, zip

jayanth.kurup

This post was written by Jayanth Kurup. A Microsoft SQL Server Consultant and Trainer based out of Bangalore, India. Jayanth has been working on MS SQL Server for over 15 years. He is a performance tuning and Business Intelligence expert. Having worked with companies like Microsoft, DELL, Wells Fargo, Thomson Reuters and many other fortune 100 companies. Some other technologies Jayanth works on include Microsoft Azure, PowerBI, Python and AWS. When he isn’t consulting or training, Jayanth like to travel, paint and read. He is also very active in social causes and the founder of Enabled Business Solutions. Visit his company by clicking the link in the menu or email him directly.

Post navigation

PreviousPrevious post: Generate Create and insert scripts for database objects from within SSMS
NextNext post: Network connectivity issues AWS SQL Express instance

The Latest

  • Monty Hall Simulation using T-SQL April 5, 2022
  • Query to quickly profile a column February 7, 2022
  • Outlook 2019 keeps asking for password multiple times December 9, 2021
  • Part 2:- Learning T SQL for beginners – Datatypes September 28, 2021
  • Part 1:- Learning T SQL for beginners- SQL, Tables and Nulls September 27, 2021
  • Query to find execution time of Jobs July 28, 2021
  • A simple script to decapitalize Column names July 19, 2021
  • My personal side effects with Covishield June 27, 2021
  • Setting up and Configuring CUDA, CUDNN and PYTorch for Python Machine Learning. June 3, 2021
  • keras.utils.generic_utils’ has no attribute ‘populate_dict_with_module_objects May 30, 2021

Find By Category

  • Azure
  • Databases
  • Events
  • Performance Tuning
  • PowerBI
  • Uncategorized
  • Website Design

Archive

  • April 2022 (1)
  • February 2022 (1)
  • December 2021 (1)
  • September 2021 (2)
  • July 2021 (2)
  • June 2021 (2)
  • May 2021 (2)
  • April 2021 (5)
  • March 2021 (10)
  • January 2021 (2)
  • November 2020 (2)
  • October 2020 (3)
  • September 2020 (4)
  • August 2020 (6)
  • July 2020 (1)
  • June 2020 (32)
  • May 2020 (18)
  • April 2020 (2)
  • March 2020 (4)
  • February 2020 (5)
  • January 2020 (1)
  • December 2019 (1)
  • November 2019 (14)
  • October 2019 (3)
  • September 2019 (1)
  • July 2019 (3)
  • June 2019 (2)
  • May 2019 (1)
  • April 2019 (2)
  • March 2019 (1)
  • January 2019 (4)
  • December 2018 (2)
  • November 2018 (4)
  • September 2018 (6)
  • August 2018 (2)
  • July 2018 (3)
  • June 2018 (4)
  • May 2018 (1)
  • April 2018 (4)
  • March 2018 (3)
  • February 2018 (3)
  • January 2018 (1)
  • December 2017 (2)
  • November 2017 (4)
  • August 2017 (2)
  • July 2017 (5)
  • May 2017 (1)
  • March 2017 (3)
  • January 2017 (3)
  • December 2016 (2)
  • November 2016 (2)
  • October 2016 (4)
  • September 2016 (1)
  • August 2016 (1)
  • July 2016 (1)
  • June 2016 (1)
  • May 2016 (2)
  • April 2016 (1)
  • March 2016 (14)
  • February 2016 (10)
  • January 2016 (19)
  • December 2015 (3)
  • November 2015 (5)
  • October 2015 (10)
  • September 2015 (9)
  • August 2015 (16)
  • July 2015 (13)
  • June 2015 (4)
  • May 2015 (2)
  • April 2015 (2)
  • March 2015 (7)
  • February 2015 (3)
  • January 2015 (22)
  • December 2014 (1)
  • November 2014 (5)
  • October 2014 (12)
  • September 2014 (5)
  • August 2014 (7)
  • July 2014 (41)
  • June 2014 (9)
  • May 2014 (12)
  • April 2014 (32)

Members Only

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly powered by WordPress