Business rules are incredibly important to every organisation. They can be made application independent by placing them in a MySQL database. When creating an application that uses business rules there is a very important point that a programmer should remember: the business rules should not be built into the application. Business rules should be made available to the application, but not hard coded into it. The reasons for this are: 1- business rules evolve 2- situations change (for example new regulations) 3- the business rules may be used by more that one application The last thing that the programmer wants is to create new application releases every time that a business rule is added or updated. And that's where MySQL comes in. ![](https://steemitimages.com/DQmYusMopng4J59bibQEpb1HvxgF9kPJ9VoeccnW4xQS2d1/image.png) <h3>MySQL and Business Rules</h3> The aim of the business rule programmer is to create a two-tier application consisting of: 1- the business rule layer 2- the application layer A MySQL database is an obvious choice for the business rule layer because it can be accessed from most programming languages and the programmer can: 1- store the business rule information in tables and/or 2- use stored stored functions to run the business rules (anyone unsure of how to create a MySQL stored function should read MySQL Stored Procedures and Functions) By using a MySQL database the programmer can create a set of business rules that can be used by any application that needs to be developed, whether that be a desktop application (perhaps using C#, C++ or VB) or an Internet application (perhaps using .NET or PHP). <h3>Creating a Simple MySQL Stored Function Business Rule</h3> The business rules themselves can be built into a MySQL function. Obviously it may write to any database table as require, but at its simplest level it can just be a series of if..then..else statements. In this example the function returns the appropriate action depending on the input from the user: <code>delimiter // drop function if exists business_rule; create function business_rule (status varchar(50)) returns varchar(50) deterministic begin declare new_status varchar(50); if status = "new" then set new_status = "case opened - send to engineer"; elseif status = "fixed" then set new_status = "problem solved - inform customer"; elseif status = "nofix" then set new_status = "problem unresolved - sent to engineer"; elseif status = "raise" then set new_status = "problem escalated - inform manager"; elseif status = "close" then set new_status = "case closed"; else set status = "undefined"; end if; return new_status; end // delimiter ;</code> This function can now be used as required by the programmer. For example it can be run from the command line (as shown in figure 1 at the bottom of this article): <code>echo "select business_rule('new')" | mysql -uuser -ppassword business_rules_db</code> Or it can be used in languages such as C#. But however the business rules are to be use the key things to remember are: 1- those business rules are now available to any programming language or application that can interface with a MySQL database 2- the business rules can be updated and added to without having to change the client application And so, at the end of this process, the programmer will have a powerful and adaptable set of business rules that are independent of the application that will use them. <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@haig/how-to-use-business-rules-in-a-mysql-database-using-mysql-functions-to-create-two-tier-business-savvy-applications">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
post_id | 19,864,434 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
author | haig | ||||||||||||||||||||||||||||||||||||||||||||||||
permlink | how-to-use-business-rules-in-a-mysql-database-using-mysql-functions-to-create-two-tier-business-savvy-applications | ||||||||||||||||||||||||||||||||||||||||||||||||
category | utopian-io | ||||||||||||||||||||||||||||||||||||||||||||||||
json_metadata | "{"type": "tutorials", "repository": {"id": 24494032, "watchers": 2288, "events_url": "https://api.github.com/repos/mysql/mysql-server/events", "forks": 948, "name": "mysql-server", "issues_url": "https://api.github.com/repos/mysql/mysql-server/issues{/number}", "trees_url": "https://api.github.com/repos/mysql/mysql-server/git/trees{/sha}", "fork": false, "git_url": "git://github.com/mysql/mysql-server.git", "assignees_url": "https://api.github.com/repos/mysql/mysql-server/assignees{/user}", "size": 1475749, "owner": {"id": 2452804, "following_url": "https://api.github.com/users/mysql/following{/other_user}", "starred_url": "https://api.github.com/users/mysql/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mysql/subscriptions", "repos_url": "https://api.github.com/users/mysql/repos", "login": "mysql", "gists_url": "https://api.github.com/users/mysql/gists{/gist_id}", "followers_url": "https://api.github.com/users/mysql/followers", "received_events_url": "https://api.github.com/users/mysql/received_events", "type": "Organization", "avatar_url": "https://avatars1.githubusercontent.com/u/2452804?v=4", "site_admin": false, "organizations_url": "https://api.github.com/users/mysql/orgs", "gravatar_id": "", "events_url": "https://api.github.com/users/mysql/events{/privacy}", "url": "https://api.github.com/users/mysql", "html_url": "https://github.com/mysql"}, "forks_count": 948, "git_refs_url": "https://api.github.com/repos/mysql/mysql-server/git/refs{/sha}", "blobs_url": "https://api.github.com/repos/mysql/mysql-server/git/blobs{/sha}", "pushed_at": "2017-12-05T20:03:15Z", "watchers_count": 2288, "teams_url": "https://api.github.com/repos/mysql/mysql-server/teams", "comments_url": "https://api.github.com/repos/mysql/mysql-server/comments{/number}", "archived": false, "svn_url": "https://github.com/mysql/mysql-server", "merges_url": "https://api.github.com/repos/mysql/mysql-server/merges", "subscribers_url": "https://api.github.com/repos/mysql/mysql-server/subscribers", "issue_events_url": "https://api.github.com/repos/mysql/mysql-server/issues/events{/number}", "stargazers_url": "https://api.github.com/repos/mysql/mysql-server/stargazers", "mirror_url": null, "statuses_url": "https://api.github.com/repos/mysql/mysql-server/statuses/{sha}", "has_projects": true, "milestones_url": "https://api.github.com/repos/mysql/mysql-server/milestones{/number}", "description": "MySQL Server, the world's most popular open source database, and MySQL Cluster, a real-time, open source transactional database.", "keys_url": "https://api.github.com/repos/mysql/mysql-server/keys{/key_id}", "open_issues": 2, "compare_url": "https://api.github.com/repos/mysql/mysql-server/compare/{base}...{head}", "ssh_url": "git@github.com:mysql/mysql-server.git", "license": {"name": "GNU General Public License v2.0", "key": "gpl-2.0", "url": "https://api.github.com/licenses/gpl-2.0", "spdx_id": "GPL-2.0"}, "html_url": "https://github.com/mysql/mysql-server", "commits_url": "https://api.github.com/repos/mysql/mysql-server/commits{/sha}", "open_issues_count": 2, "stargazers_count": 2288, "branches_url": "https://api.github.com/repos/mysql/mysql-server/branches{/branch}", "full_name": "mysql/mysql-server", "forks_url": "https://api.github.com/repos/mysql/mysql-server/forks", "score": 128.36711, "deployments_url": "https://api.github.com/repos/mysql/mysql-server/deployments", "contributors_url": "https://api.github.com/repos/mysql/mysql-server/contributors", "homepage": "http://www.mysql.com/", "contents_url": "https://api.github.com/repos/mysql/mysql-server/contents/{+path}", "has_downloads": true, "collaborators_url": "https://api.github.com/repos/mysql/mysql-server/collaborators{/collaborator}", "created_at": "2014-09-26T09:31:03Z", "git_commits_url": "https://api.github.com/repos/mysql/mysql-server/git/commits{/sha}", "releases_url": "https://api.github.com/repos/mysql/mysql-server/releases{/id}", "private": false, "pulls_url": "https://api.github.com/repos/mysql/mysql-server/pulls{/number}", "git_tags_url": "https://api.github.com/repos/mysql/mysql-server/git/tags{/sha}", "notifications_url": "https://api.github.com/repos/mysql/mysql-server/notifications{?since,all,participating}", "language": "C++", "updated_at": "2017-12-09T01:03:21Z", "has_wiki": false, "downloads_url": "https://api.github.com/repos/mysql/mysql-server/downloads", "hooks_url": "https://api.github.com/repos/mysql/mysql-server/hooks", "languages_url": "https://api.github.com/repos/mysql/mysql-server/languages", "default_branch": "5.7", "labels_url": "https://api.github.com/repos/mysql/mysql-server/labels{/name}", "url": "https://api.github.com/repos/mysql/mysql-server", "has_pages": false, "tags_url": "https://api.github.com/repos/mysql/mysql-server/tags", "clone_url": "https://github.com/mysql/mysql-server.git", "archive_url": "https://api.github.com/repos/mysql/mysql-server/{archive_format}{/ref}", "has_issues": false, "issue_comment_url": "https://api.github.com/repos/mysql/mysql-server/issues/comments{/number}", "subscription_url": "https://api.github.com/repos/mysql/mysql-server/subscription"}, "pullRequests": [], "format": "markdown", "app": "utopian/1.0.0", "platform": "github", "tags": ["utopian-io", "mysql", "tutorial", "server", "sql"], "community": "utopian"}" | ||||||||||||||||||||||||||||||||||||||||||||||||
created | 2017-12-09 03:39:12 | ||||||||||||||||||||||||||||||||||||||||||||||||
last_update | 2017-12-09 03:39:12 | ||||||||||||||||||||||||||||||||||||||||||||||||
depth | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||
children | 2 | ||||||||||||||||||||||||||||||||||||||||||||||||
net_rshares | 3,917,645,590,026 | ||||||||||||||||||||||||||||||||||||||||||||||||
last_payout | 2017-12-16 03:39:12 | ||||||||||||||||||||||||||||||||||||||||||||||||
cashout_time | 1969-12-31 23:59:59 | ||||||||||||||||||||||||||||||||||||||||||||||||
total_payout_value | 9.747 SBD | ||||||||||||||||||||||||||||||||||||||||||||||||
curator_payout_value | 3.726 SBD | ||||||||||||||||||||||||||||||||||||||||||||||||
pending_payout_value | 0.000 SBD | ||||||||||||||||||||||||||||||||||||||||||||||||
promoted | 0.000 SBD | ||||||||||||||||||||||||||||||||||||||||||||||||
body_length | 3,691 | ||||||||||||||||||||||||||||||||||||||||||||||||
author_reputation | 5,828,483,287,984 | ||||||||||||||||||||||||||||||||||||||||||||||||
root_title | "How to Use Business Rules in a MySQL Database - Using MySQL Functions to Create Two-Tier Business Savvy Applications " | ||||||||||||||||||||||||||||||||||||||||||||||||
beneficiaries |
| ||||||||||||||||||||||||||||||||||||||||||||||||
max_accepted_payout | 1,000,000.000 SBD | ||||||||||||||||||||||||||||||||||||||||||||||||
percent_steem_dollars | 10,000 | ||||||||||||||||||||||||||||||||||||||||||||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
haig | 0 | 106,342,865 | 100% | ||
st3llar | 0 | 860,822,666 | 5% | ||
luigi-tecnologo | 0 | 868,451,126 | 4% | ||
yuxid | 0 | 29,974,309,511 | 45% | ||
utopian-io | 0 | 3,879,248,842,511 | 2.5% | ||
yorkchinese | 0 | 5,587,762,315 | 80% | ||
eskimokisses | 0 | 53,027,752 | 90% | ||
oliwaw | 0 | 946,031,280 | 100% |
Thank you for the contribution. It has been approved. **PS:** - you have two essential typos in your code, please update this: `echo "select business_rule('new')" | mysql -uuser -ppassword business_rules_db` ^^^ you need to add spaces after the user / password flags PS2: I thought long and hard about validating the repo, because it states explicitly about the possibility of non-Open Source **components** inside the distro. But I'm not a "cop" so I will not dive into it that much to find out if your exact code would violate those distro sub-licenses. However, to avoid complications in the future, please check first yourself before blogging....Thx You can contact us on [Discord](https://discord.gg/UCvqCsx). **[[utopian-moderator]](https://utopian.io/moderators)**
post_id | 20,087,051 |
---|---|
author | scipio |
permlink | re-haig-how-to-use-business-rules-in-a-mysql-database-using-mysql-functions-to-create-two-tier-business-savvy-applications-20171211t100031134z |
category | utopian-io |
json_metadata | "{"app": "busy/1.0.0", "community": "busy", "tags": ["utopian-io"]}" |
created | 2017-12-11 10:00:30 |
last_update | 2017-12-11 10:00:30 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2017-12-18 10:00:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 775 |
author_reputation | 32,029,897,993,437 |
root_title | "How to Use Business Rules in a MySQL Database - Using MySQL Functions to Create Two-Tier Business Savvy Applications " |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
### Hey @haig I am @utopian-io. I have just upvoted you! #### Achievements - You have less than 500 followers. Just gave you a gift to help you succeed! - Seems like you contribute quite often. AMAZING! #### Suggestions - Contribute more often to get higher and higher rewards. I wish to see you often! - Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck! #### Get Noticed! - Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions! #### Community-Driven Witness! I am the first and only Steem Community-Driven Witness. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER! - <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a> - <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a> - Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a> [![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses) **Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
post_id | 20,144,678 |
---|---|
author | utopian-io |
permlink | re-haig-how-to-use-business-rules-in-a-mysql-database-using-mysql-functions-to-create-two-tier-business-savvy-applications-20171211t213036201z |
category | utopian-io |
json_metadata | "{"app": "utopian/1.0.0", "community": "utopian", "tags": ["utopian-io"]}" |
created | 2017-12-11 21:30:36 |
last_update | 2017-12-11 21:30:36 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2017-12-18 21:30:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 1,502 |
author_reputation | 152,913,012,544,965 |
root_title | "How to Use Business Rules in a MySQL Database - Using MySQL Functions to Create Two-Tier Business Savvy Applications " |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |