连锁创建分店数据库方法
连锁软件中,数据库结构不外两种,一种是所有数据都放同一个数据库,包括总部,另一种是总部独立数据库,每个分店一个数据库,而我常用的就是独立的数据库。 这两种方法各有优势,数据放同一个数据库,各分店之间数据进行交互时会非常方便,有统计之类的,也
连锁软件中,数据库结构不外两种,一种是所有数据都放同一个数据库,包括总部,另一种是总部独立数据库,每个分店一个数据库,而我常用的就是独立的数据库。
这两种方法各有优势,数据放同一个数据库,各分店之间数据进行交互时会非常方便,有统计之类的,也是直接在数据库上操作,没那么多麻烦,不好的地方就是,数据一多,不便于维护,也得去考虑分页等问题。而第二个方法就是刚上和第一个的好坏相反,但是我觉得分开的话数据会非常清晰,维护方便,当然这只是针对我们软件数据库之间交互不多的情况,可能有的数据库之间交互数据比较频繁,就是用第一个方法,没有什么维护问题,也会选择第一,各有好坏,看各人使用。
独立数据库就得处理创建分店时怎么创建数据库的问题,因为软件是一直在更新的,也就是数据库也是一直更新,所以创建分店数据库,也必须是灵活的。
(Mssql)最早用的的方法:会在总部放一个数据库的备份文件(Bak),每次更新就是覆盖Bak文件,而创建数据库的思路,1.把model数据库备份成model.bak,2.把bak文件还原到model中,3.直接用create database 语句就可以建一个分店数据库了,4.用model.bak还原回model数据库,【注意:创建数据库时,都会以model数据库模版来创建,这里正是利用这个】
这个方法是可以实现创建分店,但是比较笨,每次更新都要在更新文件里加个数据库bak文件,而且数据库都一直在增大,虽然是空数据库,只有表结构等这些东西,但也得8M+,这在更新时带来很多麻烦,于是后面又想到一个方法,在原有基础上改进。
(Mssql)改进的方法:1.在安装软件时,会在mssql server上创建一个模版数据库,这个模版数据库也可以看作一个分店的数据库,软件更新时,会更新这个数据库,更新完会备份这个模版数据库,覆盖总部中的Bak文件,后面创建分店时怎么创建数据库的还是没变,和上面一样。这里改进的主要就是数据库模版问题,这样做的话,就不用每次更新带上数据库文件了。
最初的软件就一直使用这个方法到现在。
最近有一套新软件,在数据库的设计上又是遇到这问题,我总觉得改进过的方法也不是很方便,于是又想到下面的改进方法。
1.保持使用模版数据库,模版数据库随分店的更新一同更新,Bak文件使用不上了,作废。2.在创建分店时,先创建一个空的数据库,然后通过程序读取模版数据库的所有结构到新数据库上执行,简单点说就是通过程序来复制模版数据库的所有结构。
这样就不用再使用Bak那样的笨重文件了,而且数据库可以独立一个服务器,老方法是数据库和软件必须同一个服务器,因为要依赖放在总部里的Bak文件,而现在数据库和软件就可以脱离,模版数据库保护最新,分店创建新数据库复制模版数据库的结构,问题都解决 了。
随带说一下Mysql,因为我们软件是兼容多种数据库的,Mysql也是其中,前期mysql和mssql的思路是一样的,都是通过更新数据库文件,用数据库备份文件来创建新数据库,后面Mysql也改成这种最优的方法:1.软件安装完,自动创建一个模版数据库,2.创建新分店时,会把数据库备份成sql文件,再在程序中修改sql文件中的数据库名称,3.执行sql文件。这里mysql和mssql不一样的地方就是,mssql的复制表结构,必须一个一个去模版数据读出来再在新数据库上执行,而mysql的备份就是导出数据库的所有结构,我们只需要修改一个数据库名称为新的数据库执行。
下面附上C#里复制数据库的方法:
public void InitialData(string ModelDataBaseName, string DataBaseName) { #region 处理表和表数据 string strSql_GetUserTable = string.Format("select * from {0}.dbo.GetUserTable order by id,columnsort ", ModelDataBaseName); DataTable dt_GetUserTable = dbHelper.ExecuteQuery(CommandType.Text, strSql_GetUserTable, null).Tables[0]; if (dt_GetUserTable.Rows.Count > 0) { //id,tablename,columnsort,columnname,tablekey,columndatatype,columndatalen1 //columndatalen2,columndatafloat,allowisnull,defaultdata string tableName = ""; StringBuilder strCreateTableSql = new StringBuilder(); StringBuilder strKeySql = new StringBuilder(); StringBuilder strInsertData = new StringBuilder(); foreach (DataRow dr in dt_GetUserTable.Rows) { if (dr["tablename"].ToString() != tableName) { if (!string.IsNullOrEmpty(strCreateTableSql.ToString())) { if (strKeySql.Length > 0) { strKeySql.Remove(strKeySql.Length - 1, 1); strCreateTableSql.AppendFormat(" PRIMARY KEY CLUSTERED ( {0} )) ON [PRIMARY] ", strKeySql.ToString()); strKeySql.Remove(strKeySql.Length - 1, 1); } else { if (strCreateTableSql.ToString().EndsWith(",")) strCreateTableSql.Remove(strCreateTableSql.Length - 1, 1); strCreateTableSql.Append(" )"); } dbHelper.ExecuteNonQuery(DataBaseName, strCreateTableSql.ToString(), null); dbHelper.ExecuteNonQuery(CommandType.Text, string.Format(" insert into {0}.dbo.{1} select * from {2}.dbo.{1} ", DataBaseName, tableName, ModelDataBaseName), null); } tableName = dr["tablename"].ToString(); strCreateTableSql.Clear(); strCreateTableSql = new StringBuilder(); strKeySql.Clear(); strKeySql = new StringBuilder(); strCreateTableSql.AppendFormat(" create table {0} (", tableName); } strCreateTableSql.Append(dbHelper.GetDataType(dr["columnname"].ToString(),dr["columndatatype"].ToString(), dbHelper.GetInt(dr["columndatalen2"].ToString()), dbHelper.GetInt(dr["columndatafloat"].ToString()), dr["allowisnull"].ToString(), dr["tablekey"].ToString(),ref strKeySql)); } if (!string.IsNullOrEmpty(strCreateTableSql.ToString())) { if (strKeySql.Length > 0) { strKeySql.Remove(strKeySql.Length - 1, 1); strCreateTableSql.AppendFormat(" PRIMARY KEY CLUSTERED ( {0} )) ON [PRIMARY] ", strKeySql.ToString()); strKeySql.Remove(strKeySql.Length - 1, 1); } else { if (strCreateTableSql.ToString().EndsWith(",")) strCreateTableSql.Remove(strCreateTableSql.Length - 1, 1); strCreateTableSql.Append(" )"); } dbHelper.ExecuteNonQuery(DataBaseName, strCreateTableSql.ToString(), null); dbHelper.ExecuteNonQuery(CommandType.Text, string.Format(" insert into {0}.dbo.{1} select * from {2}.dbo.{1} ", DataBaseName, tableName, ModelDataBaseName), null); } } #endregion #region 存储过程、视图、函数、触发器 StringBuilder strSql = new StringBuilder(); strSql.AppendFormat(" select name,type,definition from {0}.dbo.GetUserPV ",ModelDataBaseName); DataTable dt_GetUserPV = dbHelper.ExecuteQuery(CommandType.Text, strSql.ToString(), null).Tables[0]; if (dt_GetUserPV.Rows.Count > 0) { StringBuilder strTest = new StringBuilder(); foreach (DataRow dr in dt_GetUserPV.Rows) { dbHelper.ExecuteNonQuery(DataBaseName, string.Format("{0}", dr["definition"].ToString()), null); } } #endregion }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

All the software on my friend's computer has been opened using WPS and cannot run normally. All exes cannot be opened, including the task manager, registry, control panel, settings, etc. When opened, all WPS garbled characters appear. This situation cannot be done remotely. The remote software is also an exe, which seems to be unsolvable. Let’s take a look at how 20 operates to restore the computer to normal. This is because the opening method of the exe has been changed to WPS, and you only need to restore the default opening method. Er0 exports the exe registry information on a normal computer and puts it on the website. Because the browser can be opened, please guide your friends to open our website, copy the registry information, create a new text document on the desktop, and save it as [File name: 1.reg; Save type: All files (*.

In the field of folding screens, small folding screens are also loved by many young users due to their lightweight, portable, exquisite and compact fashion attributes. In the previous review of the Samsung Galaxy Z Fold6 large folding screen, I gave it a "more square and more AI" evaluation. The small folding screen released at the same time, Samsung Galaxy Z Flip 6, has also attracted much attention. So what will it be like? Today, let’s unlock this new fashion product together. "Light" design: The fashionable appearance on the fingertips is the same as Galaxy Z Fold 6. The Galaxy Z Flip 6 body adopts a square design. In the unfolded state, the fuselage is slender than the average candy bar machine. The front and rear are connected by a straight-sided middle frame, and the four R corners retain a rounded shape.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.
