Data Modeling and Program Design Experiment Report [Complete Works]-Customer Delivery

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 drawing polylines is really desperate. The new version cancels many functions. It is recommended to use the old version.

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

Each person chooses a topic to construct the conceptual model, logical model and physical model of the database:

I chose 10, and there are experimental data for all topics and a detailed report 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 (travel agent)
7. Payroll management 15. Student management (student results)
8. Vehicle rental (vehicle management)  

Some students retreat as soon as they see the experiment and the course design. In fact, they can understand after spending some time carefully studying the experiment template given by the teacher.

Experiment 1 Familiar 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 tools VP.

2. Experimental content

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

     1) Install the data modeling tool EA, and be familiar with the Visio tool software according to the EA usage document. Practice building a simple data model.

     2) Install the data modeling tool Visio, and be familiar with the Visio tool software according to the Visio usage document. Practice building a simple data model.

     3) Install the data modeling tool VP, and be familiar with the VP tool software according to the VP usage document. Practice building a simple data model.

2. Take Visio as an experimental example

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

1. The purpose of the experiment

  1. Construct a conceptual model of the database based on actual cases;
  2. Construct a logical model based on the conceptual model.

2. Experimental content

  1. Establish conceptual models (entity attribute diagrams, ER diagrams of binary relations).
  2. Combine the partial ER diagrams into an overall ER model.
  3. Add diversity constraints in the ER model.
  4. Establish an ER model that displays the primary key.
  5. Identify the attributes of the entity, confirm the primary key, foreign key, and alternate key

Three, experimental realization

     1. Part of the ER model

     2. Overall ER model

 

     3. Add diversity constraints in the ER diagram

     4. Identify the primary key in the ER diagram

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

 Experiment 3 Use data modeling tools to create physical models

1. The purpose of the experiment

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

2. Experimental content

      When we complete the logical design, the entities and attributes it contains are all descriptive texts as names. Therefore, the first task is:

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

      2) For naming rules, especially for abbreviation style, consistency is the most important. Use simple names as much as possible, and don't use keywords or reserved words.

      3) Separate words can use underscore (_) or the initial letter of the word in the form of capitalization.

Three, 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. According to the physical model, proficient in creating databases on the database system.

2. Experimental content

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

  1. Proficiency in installing and using Mysql;
  2. Create a system database based on the physical model on the Mysql management system;
  3. Export the created database script;
  4. According to the established database, use your familiar programming language (such as Java, C++, C#, etc.) to write database connection statements to realize the addition, deletion, and modification of each table, and realize the table association relationship.

Three, experimental realization

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

Knowledge to be mastered:     

①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 (that is, a class is deleted), and there happens to be students of that class in the student table, an error will be reported and deletion is not allowed.

        When the external 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 external 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, the cno of these corresponding data is set to NULL.

②Data type

        Binary[(n)] is fixed binary data with n bits. Among them, the value of n ranges from 1 to 8000. The size of its storage scent is n + 4 bytes. It is not a function, but a type conversion operator. It is used to force the string after it to be a binary string, which can be understood as case-sensitive when comparing strings.    

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

        Blob (Binary Large Object) has a maximum length of 65535Bit (2^16-1), which is a maximum of 65K. A binary large object is a container that can store binary files. A typical BLOB is a picture or a sound file. Due to their size, they must be processed in a special way (for example: upload, download or store in a database). According to Eric Raymond, the main idea of ​​processing BLOBs is to let file processors (such as database managers) not care about what the file is, but care about how to deal with it. However, some experts emphasized that this method of processing 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 reduce the performance of the database. Storing large multimedia objects in the database is a typical example of BLOB processing by applications.

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

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

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

        The 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 program. For example, applications can use BMP, TIEF, GIF, and JPEG formats to store data in the Image data type.

        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 is after; the latter data type is time before and date is 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 stored in Datetime (yyyy-mm-dd hh:mm:ss) 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 stored by Smalldatetime is: '1900-01-01 ~ 2079-12-31' (each value requires 4 storage bytes).   

        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 date format is in year, month, and day format; when Set DateFormat DMY is executed, the date format is in day, month, and year format.

        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 inserted data or date and time. The timestamp refers to the total number of seconds since 00:00:00, January 1, 1970, Greenwich Mean Time (08:00, 01:01, 1970, 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 is composed of 16-byte hexadecimal numbers, representing a globally unique one. GUID is very useful when the record row of the table is required to be unique. For example, using this data type in the customer identification number column can distinguish different customers.

        Geometry can store all geometry types

        GEOMETRYCOLLECTION any geometric collection

        LINESTRING simple line

        MULITILINESTRING multi-line

        MULTIPOINT Multipoint

        Many aspects of MUILITIPOLYGON

        Point simple

        Polygon simple noodles

        Digital data contains only numbers, and digital data types include positive and negative numbers, decimal (floating point) and integer.
        Integers consist of positive and negative integers, such as 39, 25, 0, -2, and 33967. In Micrsoft SQL Server, the data types of integer storage are Int, Smallint and Tinyint. Int data type storage data range is larger than Smallint data type storage data range, and Smallint data type storage data range is larger than Tinyint data type storage data range.

        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 storage space).   

        The data types accurate to decimals in SQL Server are Decimal and Numeric. The storage space occupied by this data is determined by 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, the one-third score is recorded as 0.3333333, which cannot be accurately represented 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 (approximately)

        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: distinguish case. It is variable-length character data, and its length does not exceed 8KB.

        Char(N)[binary] N=1~255 characters, binary: distinguish case. It is fixed-length character data, and its length is up to 8KB. ASCII data exceeding 8KB can be stored using the Text data type. For example, because Html documents are all ASCII characters and are generally longer than 8KB in length, these documents can be stored in SQL Server in the Text data type.

        In Microsoft SQL Server, traditional non-Unicode data types allow the use of characters defined by a specific character set. During the SQL Server installation process, 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 the Unicode data type, it takes up twice the size of the non-Unicode data type.
        In SQL Server, Unicode data is stored in Nchar, Nvarchar, and Ntext data types. Columns stored using this character type can store characters in multiple character sets. When the length of the column changes, the Nvarchar character type should be used. At this time, up to 4000 characters can be stored. When the length of the column is fixed, the Nchar character type should be used. Similarly, at this time, up to 4000 characters can be stored. When using the Ntext data type, this 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. When it indicates true or false, ON or OFF, the Bit data type is used. For example, asking whether it is a client request for every visit can be stored in a column of this data type.

        Enum (Enumeration) single choice, 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').

note:

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

     2. The script to export the created database is:

     If MySql reports an error when exporting:

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 install the mysql path 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 check:

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 blog.csdn.net/qq_41587612/article/details/106990751