Data sheet, you are beautiful I do not love

Source: Internet
Author: User
Tags integer numbers

Why do we need to learn a data sheet? This answer is actually very simple, just think about it. parsing:If there is no data table, then the keyword, primary key, index and so on can not be discussed. In a database artboard, you can display all of the data tables in a database (even those that are not created with PowerBuilder), create data tables, modify table definitions, and so on, which are a very important object in a database, and are the foundation of other objects. a data table (or table) is one of the most important components of a database. A database is just a framework, and a data table is its substance. As in the "Teaching management system", the "Teaching Management" database contains 6 data tables on a specific topic: "Teacher" table "course" table, "scores" table, "student" table, "Class" Table and "lectures" table, to manage the teaching process of students, teachers, courses and other information. These separate data sheets are connected by building relationships and become a database that can be cross-checked and at a glance. principles of building a tableparsing:In order to reduce the data entry errors and make the database work efficiently, the table design should classify the information according to certain principles, and also to ensure the rationality of the table structure design, and usually to standardize the table to eliminate the redundancy in the table, ensure that a table is only around one topic and make the table easy to maintain.
Principles of information classificationparsing: Each table should contain only information about a topicwhen each table contains only information about a topic, you can maintain the information for that topic independently of other topics. For example, you should keep the teacher's basic information in the teachers table. If you save the basic information in the "Lessons" table, deleting the instructor's message will delete the basic information. The table should not contain duplicate informationthere should be no duplication between the tables. Each piece of information is only available in one table, and it is more efficient to update it only in one place when needed. For example, information about each student's name, gender, and so on is saved only in the students table, and the information is no longer saved in grades. say so much, you look at these watches, pretty bar. The following describes the contents of the data table:Four types of integrity constraints

Entity integrity: Integrity set for data rows

Domain integrity: The integrity of the data column settings.

Referential integrity: FOREIGN KEY constraints

Custom integrity: In order to meet our business needs, our own tailored integrity constraints, general

through stored procedures.

data types in SQL Server

int: Storing integer numbers

Numeric (18, 2): Storing decimals

Decimal (18, 2): Stores decimals

nvarchar (): Storing text

As long as the string is saved with the nvarchar () type, n represents the Unicode encoding, the encoding is an international universal encoding, can avoid garbled appearance.

var represents variable length. The actual contents of the column in the table are the space of its own, not the space occupied by that column by the length set by (20).

varchar (): Storing variable-length text

CHAR (4): Storing fixed-length text

nvarchar (Max)

DateTime: Save date and time

Photo: Image (binary storage)

Storage name: nvarchar (20)

--Storage Age: Int

--Storage gender: bit

--Save one article: nvarchar (max)

Attention:

Use ntext or text because the text and ntext are very inefficient to read.

Establish a constraint on a table

PRIMARY KEY constraint

A table be sure to set the primary key

Non-null constraint

03. Default Value Constraints

04.check constraints

05. FOREIGN KEY constraints

NOTE: FOREIGN KEY constraints can only be set in the external key table

Primary key:
For distinguishing other entities, the value of the primary key cannot be duplicated in the same table

FOREIGN key:One of the columns in table A is the primary key, but in the other table B, the column is not a primary key. Table A is called the primary key table, and table B is called the Foreign key table.

Considerations for primary foreign key establishment

You cannot add records to a child table when there are no corresponding records in the primary table

--No number in the Student information table that does not exist in the score table

You cannot change the values in the primary table and cause the records in the child table to be orphaned

--Change the number of students in the Student information table, and the student's score list should be changed.

The child table has a record corresponding to the primary table, and the row cannot be deleted from the primary table

--You can't delete a student with a score.

Delete the primary table before deleting the child table

--Delete The student's information form before deleting the students ' score form

Wildcard characters:

Parse: "_": there is only one character.

"%": any character of any one.

The above two special characters are generally used in conjunction with like.

These are my summary of the core content, or very hard, there is a leak of the place hope that you add

Data sheet, you are beautiful I do not love

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.