Data Modeling and Programming Experiment Report【Complete Works】-Customer Shipping

If this article is helpful to you, please like and follow me!

I use Eclipse + Visio2010 + MySQL Workbench, you can also use EA (Enterprise Architect), VP (Visual Paradigm) or online drawing tools instead of Visio. The "intelligence" of Visio's polyline drawing is really disappointing. The new version has canceled many functions, and it is recommended to use the old version.

4-hour experiment: ①Familiar with using data modeling tools ; ②Using data modeling tools to create conceptual and logical models ; ③Using data modeling tools to create physical models ; ④Creating databases on Mysql based on physical models

Each candidate chooses a topic to build the conceptual model, logical model and physical model of the database:

I chose 10, and there are experimental data for all topics and detailed reports for 10 below.
1. Customer order entry 9. Student accommodation
2. Inventory control 10. Client transportation
3. Asset management 11. Publisher printing
4. Project management 12. Country library
5. Course management 13. Real estate rentals
6. Human resource management 14. Travel agent
7. Payroll management 15. Student results
8. Vehicle management  

Some students retreated when they saw the experiment and class design. In fact, they could understand it after spending some time studying the experiment template given by the teacher.

Experiment 1 Familiarize yourself with using data modeling tools

1. The purpose of the experiment

  1. Master the use of data modeling tool EA;
  2. Master the use of data modeling tool Visio;
  3. Master the use of data modeling tool VP.

2. Experimental content

1. Experiment requirements (choose one of the following three tools)

     1) Install the data modeling tool EA, and familiarize yourself with the Visio tool software according to the EA documentation. Practice building simple data models.

     2) Install the data modeling tool Visio, and familiarize yourself with the Visio tool software according to the Visio documentation. Practice building simple data models.

     3) Install the data modeling tool VP, and familiarize yourself with the VP tool software according to the VP usage documentation. Practice building simple data models.

2. Take Visio as an experimental example

Experiment 2  uses data modeling tools to create conceptual and logical models

1. The purpose of the experiment

  1. Build a conceptual model of the database based on actual cases;
  2. Build logical models from conceptual models.

2. Experimental content

  1. Build conceptual models (entity attribute diagrams, ER diagrams of binary relationships).
  2. Combine the local ER diagrams into a global ER model.
  3. Add diversity constraints to the ER model.
  4. Build an ER model that displays the primary key.
  5. Identify attributes of entities, confirm primary keys, foreign keys, alternate keys

3. Experimental realization

     1. Part of the ER model

     2. Holistic ER Model

 

     3. Fill in the diversity constraint in the ER diagram

     4. Identify the primary key in the ER diagram

     5. Identify entity attributes, confirm primary key, foreign key, alternate key

 Experiment 3 Create a physical model using data modeling tools

1. The purpose of the experiment

  1. Master the use of a database operating system;
  2. Create a physical model from a logical model.

2. Experimental content

      When we complete the logical design, the entities and properties it contains are named with full descriptive text. So the first task is:

      1) To shorten these names of entities and attributes to make it simple, and to ensure that the physical model will not cause any table name or column name length problems.

      2) For naming conventions, especially for abbreviated styles, consistency is most important. Use simple names as much as possible, and don't use keywords or reserved words.

      3) Separate words can use underscore (_) or capital letters.

3. Experimental realization

Experiment 4 Create a database on Mysql based on the physical model

1. The purpose of the experiment

  1. Master the use of database systems;
  2. Proficiency in creating databases on database systems based on physical models.

2. Experimental content

     Apply what you have learned to create a Mysql database. Require:

  1. Proficient in installing and using Mysql;
  2. Create a system database according to the physical model on the Mysql management system;
  3. Script to export the created database;
  4. According to the established database, use the programming language you are familiar with (such as Java, C++, C#, etc.) to write the connection database statement, realize the addition, deletion, modification and query of each table, and realize the table association relationship.

3. Experimental realization

     1. According to the physical model, the created system database is:

Required knowledge:     

①Define foreign code operation

       When the foreign code is defined as the restrict keyword, if a piece of data is deleted from the class table (ie, a class is deleted), and there are students in the class in the student table, an error will be reported and deletion is not allowed.

        When the foreign code is defined as the cascade keyword, it means cascade deletion. When deleting a piece of data in the class table, the corresponding data in the student table will be deleted together.

        When the foreign code is defined as the set null keyword, it means that when deleting a piece of data in the class table, if there is corresponding data in the student table, set the cno of the corresponding data to NULL.

②Data type

        Binary[(n)] is n-bit fixed binary data. where n ranges from 1 to 8000. Its storage size is n + 4 bytes. It is not a function, it is a type conversion operator, which is used to force the string behind it to be a binary string, which can be understood as being case-sensitive when comparing strings.    

        Varbinary[(n)] is n-bit variable-length binary data. where n ranges from 1 to 8000. The size of its storage is n+4 bytes, not n bytes.

        Blob (Binary Large Object) has a maximum length of 65535Bit (2^16-1), that is, a maximum of 65K. A binary large object is a container that can store binary files. A typical BLOB is an image or a sound file that, due to their size, must be handled in a special way (eg, uploaded, downloaded, or stored in a database). According to Eric Raymond, the main idea of ​​dealing with BLOBs is to let file processors (such as database managers) not care what the file is, but how to deal with it. However, some experts emphasized that this method of dealing with large data objects is a double-edged sword, and it may cause some problems, such as the storage of binary files that are too large, which will degrade the performance of the database. Storing large multimedia objects in the database is a typical example of application processing BLOB.

        The maximum length of LongBlob is 4294967295Bit (2^32-1). The maximum length is 4G.

        The maximum length of MediumBlob is 16777215Bit (2^24-1), that is, the maximum length is 16M.

        TinyBlob maximum 255Bit (2^8-1).         

        Data stored in the Image data type is stored as a bit string, not interpreted by SQL Server, but must be interpreted by the application. For example, an application can store data in the Image data type using the BMP, TIEF, GIF, and JPEG formats.

        Date and time data types consist of valid dates and times. For example, valid date and time data includes "4/01/98 12:15:00:00:00 PM" and "1:28:29:15:01AM 8/17/98". The former data type is date before and time after; the latter data type is time before and date after. In Microsoft SQL Server, date and time data types include Datetime and Smalldatetime.

        The time range that Date (yyyy-mm-dd) can store is: '1000-01-01' ~ '9999-12-31'.

        The date range of Datetime (yyyy-mm-dd hh:mm:ss) stored in SQL Server is: ' 1753-01-01 ~ 9999-12-31 ' (each value requires 8 storage bytes). The time range that can be stored in MySQL is: '1000-01-01 00:00:00.000000' ~ '9999-12-31 23:59:59.999999'.

        The date range that Smalldatetime stores is: '1900-01-01 ~ 2079-12-31 ' (each value requires 4 bytes of storage).   

        Time(hh:mm:ss)

        The format of the date can be set. The command to set the date format is as follows:
        Set DateFormat {format | @format_var}
        where format | @format_var is the order of the date. Valid parameters include MDY, DMY, YMD, YDM, MYD, and DYM. By default, the date format is MDY.
        For example, when Set DateFormat YMD is executed, the format of the date is in the form of year, month, and date; when Set DateFormat DMY is executed, the format of the date is in the form of day, month, and year.

        Timestamp Timestamp (yyyy-mm-dd hh:mm:ss), used to indicate the sequence of SQL Server activities, expressed in binary projection format. Timestamp data has nothing to do with insert data or date and time. The timestamp refers to the total number of seconds from January 01, 1970 00:00:00 Greenwich Mean Time (January 01, 1970 08:00:00 Beijing Time) to the present. The time range that can be stored in MySQL is: '1970-01-01 00:00:01.000000' ~ '2038-01-19 03:14:07.999999'.

        Year(yyyy)

        Uniqueidentifier consists of a 16-byte hexadecimal number, representing a globally unique. GUIDs are useful when table rows are required to be unique. For example, using this data type in the Customer ID column can distinguish different customers.

        Geometry can store all geometry types

        GEOMETRYCOLLECTION any geometry collection

        LINESTRING simple line

        MULITILINESTRING Multiline

        MULTIPOINT Multipoint

        MUILITIPOLYGON in many ways

        Point is simple

        POLYGON Simple Noodles

        Numeric data contains numbers only, and numeric data types include positive and negative numbers, decimals (floating point numbers), and integers.
        Integers consist of positive and negative integers, such as 39, 25, 0, -2, and 33967. In Micrsoft SQL Server, integer storage data types are Int, Smallint and Tinyint. The Int data type stores data in a larger range than the Smallint data type stores data, and the Smallint data type stores data in a larger range than the Tinyint data type stores data.

        BigInt[M] -2^63~2^63-1,UNSIGNED:0~2^64。

        Int[M] -2^31~2^31-1 is -2 147 483 648 to 2 147 483 647, UNSIGNED: 0~2^32 (each value requires 4 bytes of storage space).

        MediumInt[M] -8388608~8388607,UNSIGNED :0~16777215

        Smallint[M] -32768~32767, UNSIGNED: 0~65535 (each value requires 2 bytes of storage space).

        Tinyint[M] -128~127, UNSIGNED: 0~255 (each value requires 1 byte of storage space).   

        The data types in SQL Server for decimal-accurate data are Decimal and Numeric. The storage space occupied by such data is determined according to the number of digits after the decimal point of the data.
        In SQL Server, the data types for approximate decimals are Float (double precision) and Real (single precision). For example, a fraction of one third is written as 0.3333333, which cannot be represented exactly when using approximate data types. Therefore, the data retrieved from the system may not be exactly the same as the data stored in the column.

        Float[(M,D)] -3.4E+38~3.4E+38 (approx.)

        Double[(M,D)] -1.79E+308~1.79E+308( 约 )

Note: M is length, D is decimal, Float 4 bytes, Double 8 bytes

        Character data is data composed of any combination of letters, symbols, and numbers.    

        Varchar(N)[binary] N=1~255 characters, binary: case-sensitive. It is variable-length character data whose length does not exceed 8KB.

        Char(N)[binary] N=1~255 characters, binary: case-sensitive. It is fixed-length character data, and its length is at most 8KB. ASCII data larger than 8KB can be stored using the Text data type. For example, because Html documents are all ASCII characters and typically exceed 8KB in length, these documents can be stored in SQL Server as Text data types.

        In Microsoft SQL Server, traditional non-Unicode data types allow the use of characters defined by a specific character set. During SQL Server installation, a character set is allowed to be selected. Using the Unicode data type, any character defined by the Unicode standard can be stored in the column. In the Unicode standard, all characters defined in various character sets are included. Using Unicode data types takes up twice the size of using non-Unicode data types.
        In SQL Server, Unicode data is stored in Nchar, Nvarchar, and Ntext data types. Columns stored using this character type can store characters from multiple character sets. When the length of the column changes, the Nvarchar character type should be used, which can store up to 4000 characters. When the length of the column is fixed, the Nchar character type should be used, and again, a maximum of 4000 characters can be stored. When using the Ntext data type, the column can store more than 4000 characters.

        LongText maximum length 4294967295Bit (2^32-1)

        MediumText maximum length 16777215Bit (2^24-1)

        Text maximum length 65535Bit (2^16-1)

        TinyText maximum length 255Bit (2^8-1)

        Bit consists of 1 or 0. The Bit data type is used when representing true or false, ON or OFF. For example, a client request asking if it is each access can be stored in a column of this data type.

        Enum (Enumeration) radio, the maximum number of sets is 65535. Example: sex enum(1,0).

        Set check, the maximum number of sets is 64. Example: habby set('playing video games', 'sleeping', 'watching movies', 'listening to music').

Notice:

       In this experiment, my foreign codes are all set to Cascade On Delete and Cascade On Update for easy management. The primary key no (code) is all set to INT (8), and you can also set it to VARCHAR type.

     2. The script to export the created database is:

     If MySql exports an error:

WARNING
 
mysqldump.exe is version 5.5.16, but the MySQL Server to be dumped has version 5.6.13.
 
Because the version of mysqldump is older than the server, some features may not be backed up properly.
 
It is recommended you upgrade your local MySQL client programs, including mysqldump to a version equal to or newer than that of the target server.
 
The path to the dump tool must then be set in Preferences -> Administrator -> Path to mysqldump Tool:
 
11:22:10 Dumping db-bug (all tables)
 
Running: mysqldump.exe --defaults-extra-file="c:\users\admini~1\appdata\local\temp\tmpilpxbj.cnf"  --user=root --max_allowed_packet=1G --host=localhost --port=3306 --default-character-set=utf8 --single-transaction=TRUE "db-bug"
 
mysqldump: Couldn't execute 'SET OPTION SQL_QUOTE_SHOW_CREATE=1': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_QUOTE_SHOW_CREATE=1' at line 1 (1064)

      Solution:

      Set Edit -> Preferences -> Administrator -> Path to mysqldump Tool to the mysql path installed by yourself D:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe

      3. The statement to connect to the database is:

import java.sql.Connection;
import java.sql.DriverManager;

public class Test {
	public static void main(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?characterEncoding=UTF8&useSSL=false", "root", "jk198205");
		System.out.println("连接成功");
		conn.close();
	}
}

      4. The realization of table addition, deletion, modification and query:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

public class Test {
	public static void main(String[] args) throws Exception {
		Connection conn = null;
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/test?characterEncoding=UTF8&useSSL=false", "root","");
		System.out.println("连接成功");
		insertData(conn);
		fetchData(conn);
		upData(conn);
		fetchData(conn);
		deleteData(conn);
		fetchData(conn);
		conn.close();
	}

	public static void fetchData(Connection conn) {// 读取数据
		try {
			Statement stm = (Statement) conn.createStatement();
			String sql = "select * from office";
			ResultSet re = stm.executeQuery(sql);
			while (re.next()) {
				int no = re.getInt("no");
				String address = re.getString("address");
				String tel = re.getString("tel");
				String fax = re.getString("fax");
				System.out.print("no: " + no);
				System.out.print(", address: " + address);
				System.out.print(", tel: " + tel);
				System.out.print(", fax: " + fax);
				System.out.print("\n");
			}
			re.close();
		} catch (SQLException se) {
			se.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("成功读取数据!" + "\n");
		}
	}
	
	public static void insertData(Connection conn) {// 插入数据
		try {
			String sql = "insert into office (no,address,tel,fax) values(?,?,?,?)";
			PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
			pst.setInt(1, 20170418);
			pst.setString(2, "北京市朝阳区233弄");
			pst.setString(3, "12344455523");
			pst.setString(4, "33333333333");
			pst.executeUpdate();
			pst.close();
		} catch (SQLException se) {
			se.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("成功插入数据!" + "\n");
		}
	}

	public static void upData(Connection conn) {// 修改数据
		try {
			String sql = "update office set fax = ? where no = ?";
			PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
			pst.setString(1, "55555555555");
			pst.setInt(2, 20170418);
			pst.executeUpdate();
			pst.close();
		} catch (SQLException se) {
			se.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("成功修改数据!" + "\n");
		}
	}

	public static void deleteData(Connection conn) {// 删除数据
		try {
			String sql = "delete from office where no = ?";
			PreparedStatement pst = (PreparedStatement) conn.prepareStatement(sql);
			pst.setInt(1, 20170418);
			pst.executeUpdate();
			pst.close();
		} catch (SQLException se) {
			se.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			System.out.println("成功删除数据!" + "\n");
		}
	}
}

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324233958&siteId=291194637