Click here to Skip to main content
15,889,898 members
Articles / Database Development / MySQL

What are the Major Parts of a SQL DB?

Rate me:
Please Sign up or sign in to vote.
4.17/5 (3 votes)
14 Aug 2019MIT3 min read 5.8K   1
This post discusses the major parts of a SQL database

A SQL database is used to store and retrieve data. The database is housed in a database server and largely controlled by a database management system. All SQL databases, whether they are MS SQL Server, MySQL, Oracle, or Progress have several components in common. They are:

  • Tables
  • Indexes
  • Views
  • Stored Procedures
  • Triggers

It is these various pieces that are used to house, retrieve, and process data with the SQL database.

SQL Database Tables

Tables are used to store data within the database. They are its main component and without them, the database would serve little purpose. Tables are uniquely named within a database. Many operations, such as queries use these names. Typically, a table is named to represent the type of data stored within.

For example, a table holding employee data may be called Employees. A table consists of rows and columns. The columns are defined to house a specific data type, such as dates, numeric, or textual data. Each column is also given a name. Continuing with our example, an employee’s name may be defined in the table as two columns as FirstName and LastName.

Indexes

Indexes are used to make data retrieval faster. Rather than having to scan an entire table for data, an index allows the database to, essentially, directly retrieve the data being asked of it. An index consists of keys, which in most cases directly relate to columns in a table.

For example, we could create an index using FirstName and LastName to make it quicker to look up employees by their name. One common property of an index is uniqueness. If an index is unique, then it can only contain unique values for its defined keys. In our employee example, this wouldn’t be practical, as a company may have more than one John Smith working in it; however, it would make sense to create a unique index on employee number.

Views

Relationships between SQL database tables can become quite complicated as data is stored in separate tables. Views help combat this issue by allowing the database administrator to create “canned” or pre-built queries that developers, report writer, and users can use in their own database queries. In this way, the view hides some of the database complexity. This makes it easier to read queries; however, danger does lurk in this as it can be easy to forget the amount of processing a view represents.

Stored Procedures

There are many situations where queries alone are insufficient to solve a problem. In these cases, developers rely on programming languages to process logic, to loop through records, and perform conditional comparisons as required. These programs can be stored in the SQL database as stored procedures.

The language used to create the stored procedures are vendor specific. T/SQL is the language used by Microsoft SQL Server; whereas, PL/SQL is used by Oracle. In each case, the language provides the same basic abilities, such as being able to move record by record through a query, perform if-then logic, and call special built in functions to assist with complicated calculations.

Triggers

Triggers are special instructions that are executed when important events, such as inserting or updating records in a table happen. The most common triggers are Insert, Update, and Delete triggers. Two items define a trigger on a table: a stored procedure and an event, such as inserting a record that invokes its execution.

In our employee example, we may want to keep track every time an employee record is updated. To do this, you could create an update trigger which calls a stored procedure to update the affected row’s modification date. Triggers are useful to ensure that data is updated consistently. You don’t have to rely on the user or program that originally modified the employee to also modify the date.

Remember! I want to remind you all that if you have other questions you want answered, then post a comment or tweet me. I’m here to help you.

The post What are the Major Part of a SQL DB? appeared first on Essential SQL.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Easy Computer Academy, LLC
United States United States
Hello my name is Kris. I’m here because I am passionate about helping non-techie people to overcome their fear of learning SQL.

I know what it is like to not know where to start or whether the time spent learning is worth the effort. That is why I am here to help you to:
- Get started in an easy to follow step-by-step manner.
- Use your time wisely so you focus on what is important to learn to get the most value from your time.
- Answer your questions. Really! Just post a comment and I’ll respond. I’m here to help.

It wasn’t long ago that I was helping a colleague with some reporting. She didn’t know where to start and soon got overwhelmed and lost as she didn’t know SQL.

I felt really bad, as she was under pressure to get some summary information to her boss, the built-in reports were falling short, and to make them better would require her to know SQL. At that time that seemed impossible! It in dawned on me, it doesn’t have to be that way.

Then I discovered a way for anyone with the desire to easily learn SQL. I worked with my co-worker, started to teach her what I learned and soon she was able to write reports and answer her boss’ questions without getting stressed or ploughing hours into manipulating data in Excel.

It hasn’t always been easy. Sometimes the information seems abstract or too conceptual. In this case I’ve found out that a visual explanation is best. I really like to use diagrams or videos to explain hard-to-grasp ideas.

Having video, pictures, and text really help to reinforce the point and enable learning.

And now I want to help you get the same results.

The first step is simple, click here http://www.essentialsql.com/get-started-with-sql-server/

Comments and Discussions

 
GeneralMy vote of 4 Pin
Elavarasan-R16-Aug-19 3:38
Elavarasan-R16-Aug-19 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.