Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Sample database design methodology
1. SAMPLE DATABASE DESIGN
METHODOLOGY USING
MS SQL SERVER 2017
This is a sample Database Design Methodology using
MS SQL Server 2017 T-SQL scripts in which the following basic
concepts will be explained in a minimalistic but concise manner
for the DBA to understand:
1. Database Creation
2. Filegroups
3. Files
4. Tables
5. Indexes
6. Storage Considerations
Author: Wally M. Pons
E-mail: wpons@datagrupo.com
Twitter: @Datagrupo
Facebook: Datagrupo
Date Published: Sept-23-2018
Corrected/Revised on: N/A
2. DATABASE CREATION (1 OF 3)
Normally (but not necessarily), MS SQL Server Databases are by default
created with two files, one is called the primary data and the other is the
transaction log. Additional files that you create are called secondary files and
can be created when needed or at any given moment in time.
The main function of the primary data is to hold information about objects
within the database, here is a short list of the most common objects that may
be included in it:
1. Tables
2. Primary Keys
3. Indexes
4. Blobs
5. Stored Procedures
6. Triggers
7. Functions
8. Diagrams
9. Data Types
10. Defaults
11. Views
3. DATABASE CREATION (2 OF 3)
On the previous list, the first four objects appear on bold letters, this indicates
that they specifically store the data you input on the database, therefore each
one of them requires a special handling involving a Filegroup and a
secondary data file for this purpose.
The rest of the items listed can reside on the primary filegroup as they are
only stored as text and do not account on the total of records held on the
database.
To put things in perspective, a few hundreds or even thousands of those
objects (5 to 11 from the list) may account for roughly 50 MB† of data. This is
an accurate number from real world data, nevertheless, if you feel that you
require more than 50 MB then you may increase it to your needs.
† MB stands for Megabyte, it is the equivalent of 1,048,576 Bytes, a Byte can be also described as one character, this
includes spaces, special characters and punctuations marks too.
4. DATABASE CREATION (3 OF 3)
The following T-SQL shows how to create a database, please note that you
must first create the folders manually and in convenience with your
environment, which could be different to the one shown below. Please feel
free to make any changes to the script to accommodate the aforementioned.
5. FILEGROUPS
In order to have your secondary data files properly segmented, you must
create the necessary Filegroups that can hold them. Unlike a physical file, a
Filegroup is a logical structure which groups the files that compose your
database. On MS SQL Server you can create a total of 32,767 Filegroups per
database, just as the same number of physical files.
In order to keep with the good documentation practice (GDocP), always use
standardization when creating object names, similar to the “Leszynski naming
convention”, it helps you and other people to better understand your design
methodologies. Below is the T-SQL code to create the Filegroups for a table
in our “DB_SAMPLE_2017” database:
In this case the Filegroup name starts with “Fg”, then the type (Tbl=Table, PK=Primary
Key, Idx=Index, Blb=Blob / Binary data), name of the object and in cases other than
tables you must include the field name(s).
6. FILES
Once we have our Filegroups defined we proceed to create the necessary
files and assign them accordingly. Quick note: Files are also called “Devices”
by some SQL developers.
On the above T-SQL script we can see the most important details in the file creation
process from left to right:
1. NAME: (logical within SQL Server) Is the internal name of the file.
2. FILENAME: Is the physical name of the file including the extension.
3. SIZE: Is the initially physical size of the file, optionally we put a percentile growth but
it can also be specified on MB.
4. TO FILEGROUP: This is where we specify the name of the Filegroup to which the
file belongs.
7. TABLES
The following T-SQL script shows a customers table with its filegroups,
defaults (constraints), data types, Primary Key and blob field. Please feel free
to make any changes to this script to accommodate it to your needs.
8. INDEXES
The following T-SQL script shows an index by the “SSN” field, the purpose of
this is to enhance search and sorting by this field, also note that it is a NON
CLUSTERED index, which means it does not index other fields on the table, if
you require to perform the same operation by other fields you will need to
create the Filegroup + File for the new index along with the script. Please feel
free to make any changes to this script to accommodate it to your needs.
9. STORAGE CONSIDERATIONS
Finally, the database has been created and you are tentatively ready to input
data, but before you do that you also need to know how much data space can
the table hold and what would be the storage cost in MB (or GB / TB) for your
disks, after all, you don’t want to run out of space. We execute the following
T-SQL using SSMS to view the required information:
It takes 1,048,576 Bytes to complete a Megabyte, which means that by the
time you have around 3,826 records / rows of data you will also have taken
close to 1 MB of space from your physical disk.
10. THANKS / T-SQL SCRIPT DOWNLOAD LINK
Thank you for taking the time on reading this sample database design
methodology guide, I hope it was helpful to your knowledge. Please feel free
to download a copy of the T-SQL that has been used here in, it is available
from my website in a text format on the following link:
https://datagrupo.com/db_sample_2017/Create_DB_SAMPLE_2017.txt
You may also send me an email with any questions regarding this material,
which is included “As Is” and without warranty, that is unless I give you the file
in person, make a copy of it to your device and run it.
Last but not least, please follow me on twitter and/or like my facebook page
for datagrupo.
Yours truly,
Wally M. Pons