1. Concept:
A rough summary is building a database and building a table - and the operations that require graphical settings in building a database and building a table.
2. Steps
1. Log in to the database
Issues to be aware of:
If it is error code 2, it means that (mssqlserver) in the configuration file manager is not opened, you need to right-click to set it to automatic
2. Database interface
1. Create a database, right-click to create a new database
2. Create a data table after the database is established
Set the column name, data type, and whether to allow null of the data table.
When checked, allow columns to have blank values
After creating the table, exit, find the name of the table, right-click and select Edit the first 200 rows.
2.5 Problems with network connection
The default is off at the beginning, you need to open the tcp/ip protocol
If you need to set the network port later, do not use 1433, it will cause network conflicts.
3. Build a data model
Fill in the data values according to the data type of the row in turn
Field Type:
Char/nvchar/varchar
Int /bit/detecttime/decimal
4. Database Separation and Addition
If the database is in use, you need to right-click the current database - detach and move
If you want to add a file, right click on the database - append - add - select the database
5. Constraints
Concept: Check to ensure data validity
- 1. Primary key: The value is used to identify one or more fields (right click on the column to set)
For example, the grades of the middle school number course number in the student table
Both the student number and the curriculum table can be used as the primary key, and a unique constraint can be obtained by querying.
2. Identification column: The sequence used to identify and increment the table (click a row in the table to proceed, there are identification rules below, after the identification rules are clicked, there are identification columns and increments.)
Note: Identity column data type should be set to numeric type
3. Non-empty Allow null ✔ After removing, programming is not empty
4. Unique constraint: ensure that the selected row has absolutely no duplicates
5. Default constraint: Write the value to the data in advance.
6. Check constraints: the currently selected data - right click - check constraints
7. Relationships and Foreign Keys
Relationship refers to the relationship between the existing tables
Foreign key: is a constraint on the relationship
1 to 1 : An object A corresponds to an object while an object B corresponds to an object A relationship can be stored in either A or B object
1 -to-many: 1 object A corresponds to multiple objects , one object B corresponds to one object A
Many-to-many: one object a corresponds to n objects b , and one object b corresponds to m object relationship and is stored in the same relationship table.
Design relationships according to this standard
Steps to Design a Foreign Key-Relationship
- 1. Set the primary key of table A
- 2. The foreign key data in the table is set as a unique key, in the index/key
- 3. Design Relationships
Design the relationship in the b table and match the relationship with the A table
Right click on a row and column - relation - table and norm column
Note: The values of the two tables that need to be constrained need to be consistent.