Background:
During this time, I made some website programs for a tourism website. The data table is roughly as follows: Figure 1 the general situation of the database table is because it is an Access database, there are two previous data tables: tc_tourcompany and tc_subdetail, the former is the relevant information of the travel agency list (to facilitate the description, for the time being, it is also called "Head Office table". The latter is the relevant information of the subordinate business department (if any) (For the convenience of description, it is also called "subsidiary table ").
Due to business needs, I want to extend it to data tables applicable to all "company types" (such as hotels, scenic spots, scenic spots, drifting companies, entertainment and catering, air ticket agencies, transportation companies, etc, because hotels, restaurants, entertainment, air ticket agencies, and other companies may have branches or subsidiaries, the table data structure is similar. Therefore, we can use such a data table design to simplify future program development. Of course, we need to add a new column in the data table to describe the types of companies such as travel agencies, hotels, scenic spots, and entertainment companies. It is not in the scope of this article.
To facilitate future classification search and query and ensure the uniqueness of the company (including its subsidiaries), I want to add a column in the above two tables. The column name is guid. Each record is a unique and non-repeating value, similar to {9e4038c8-e965-45b1-bde1-9f06e6b280a3.. net. guid. value generated by newguid () and included in braces.
Practice:How does one automatically generate these values for each record when there is a database table record?
At first, I took a detour. When adding a guid column, I select the Data Type of this column as "Number" and select "synchronous copy ID" in "field size" on the General tab below ", "Yes (no duplicates)" is selected in the index )". I thought it would be fine to save the structure in this way. When opening all the records in the table, I found that the guid column was completely empty and there was no value! So I tried some ways to insert a unique guid value. One of the solutions is to use SQL statement updates in access, and later found that this path is not available. Solution 2 is to use ado.net programming to update table records, and the workload is not small.
Is there a better way? An occasional thought helps me find a faster and better solution, that isWhen a guid column is created in the design view, the data type is automatically numbered instead of a number! At the same time, select "synchronous replication ID" in "field size" on the General tab below, and select "Yes (no duplicates)" in the index )".
For example, Figure 2 adds a guid column to the head office directory table (tc_tourcompany table ).
Figure 3 automatically generate a guid record value after adding a guid column to the head office table (tc_tourcompany table). Figure 4 Add a guid column to the tc_subdetail table of the branch office.
Figure 5 The GUID column is added to the tc_subdetail table of the branch office (segment), and The GUID record value is automatically generated.
What will happen when new records are added in the future? After testing, it is found that access will automatically generate the guid record value. OK, perfect!
For more information:When an SQL statement is generated from access, the guid query problem occurs. The string format used in SQL Server cannot query any data.
Select * From tablename where [guid] = '2017-90ab-cdef-1234-567890abcdef'
If the column referenced by the condition string is of the guid type, the syntax used by the condition expression is slightly different: where [guid] = {guid {12345678-90ab-cdef-1234-567890abcdef} ensure that the nested braces and font size shown above are included. Note that the embedding of braces is only used for the where statement. single quotation marks must be used in the insert statement. Otherwise, the malformed guid in query error will be generated.
For more information, see ASP. NET development experience (3 )---Use the guid value as the database row IDHttp://blog.joycode.com/moslem/archive/2004/03/23/16930.aspx
Others:Export/print access database structureHttp://blog.csdn.net/johnsuna/archive/2008/05/05/2393664.aspx
Appendix:
The correspondence between the access data type and the. NET oledbtype Enumeration type
The most common data type ing list
Access type name |
Database Data Type |
Oledb type |
. NET Framework type |
Member name |
Text |
Varwchar |
Dbtype _ wstr |
System. String |
Oledbtype. varwchar |
Memorandum |
Longvarwcha R |
Dbtype _ wstr |
System. String |
Oledbtype. longvarwchar |
Number of bytes: |
Unsignedtinyint |
Dbtype _ UI 1 |
System. byte |
Oledbtype. unsignedtinyint |
Yes/No |
Boolean |
Dbtype_bool |
System. Boolean |
Oledbtype. Boolean |
Date/time |
Datetime |
Dbtype _ date |
System. datetime |
Oledbtype. Date |
Currency |
Decimal |
Dbtype_numeric |
System. Decimal |
Oledbtype. Numeric |
Decimal number: |
Decimal |
Dbtype_numeric |
System. Decimal |
Oledbtype. Numeric |
Double Precision Number: |
Double Precision number |
Dbtype_r8 |
System. Double |
Oledbtype. Double |
Automatic number (copy ID) |
Guid |
Dbtype_guid |
System. guid |
Oledbtype. guid |
Copy (ID) number: |
Guid |
Dbtype_guid |
System. guid |
Oledbtype. guid |
Automatic number (long integer) |
Integer |
Dbtype_i4 |
System. Int 32 |
Oledbtype. Integer |
Quantity: (long integer) |
Integer |
Dbtype_i4 |
System. Int 32 |
Oledbtype. Integer |
OLE object |
Longvarbinary |
Dbtype_bytes |
Array System. byte |
Oledbtype. longvarbinary |
Single precision number: |
Single precision number |
Dbtype_r4 |
System. Single |
Oledbtype. Single |
Integer: |
Smallint |
Dbtype_i2 |
System. Int 16 |
Oledbtype. smallint |
Binary |
Varbinary * |
Dbtype_bytes |
Array System. byte |
Oledbtype. Binary |
Hyperlink |
Varwchar |
Dbtype _ wstr |
System. String |
Oledbtype. varwchar |