Database (SQL Server) Managing database Tables ~ Novelty

Source: Internet
Author: User
Tags integer numbers

Speaking of " database ", I always have a sense of inexplicable, in just contact with the database let me indefinitely through, so thinking , so in a calm time and space I think back to a lot of knowledge , I do not know how you came, I sincerely hope that this summary of the database can let us all have a more progressive space.

as the title says: " database creation and Management database table ", perhaps not a novelty, but I believe there should be able to help you solve some of the problems in learning, of course, who will not be perfect, there will be different feelings, so also want to take this and we have a lot of To Exchange and share the learning database when the depressed and happy .

Well, let's go into my summary of the "database" Space-time!!!

If we're creating a database, we should know first.SQL ServerInData Type
int:Storing integer numbers
Numeric(18, 2): Storing decimals
decimal(18, 2): Store decimals (upper limit is 18 bits, before and after commas are represented as decimals)
nvarchar(): Store text                                                                                                                                                                                    Unicode encoding:
After seriously recommend everyone as long as is to save the string with the nvarchar () type, n represents the Unicode encoding, the encoding is an international universal encoding, can avoid garbled out of the

Is. 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).
Archar (): storing variable-length text
char (4): Storing fixed-length text
text (); The use of the large text type of SQL Sever2000, now 2005.2008 2012 has deserted it with a heartless heart without mercy,
nvarchar (Max) General
datetime: Save date and time
Photo:image (binary storage)

In order to let us in the initial knowledge of the database, so specifically to standardize some:
--Later we store name:nvarchar
--Storage Age:int
--Storage gender:bit: includes only two values (True, False)
--Save one article:nvarchar (max)
(note) Try not to use ntext or textbecause the text and ntext reads are very inefficient .

and secondly! for the management of table data, we certainly have some constraints, the constraints of nature is the need for relative integrity, which has a very important four kinds, let us look at it!

   .
         1. entity integrity : Integrity   set for data rows;
         2. field integrity : The integrity of the data column settings.
         3. referential integrity : FOREIGN KEY constraint
         4. : In order to meet our business needs, we customize the integrity constraints, generally through the stored procedures.

The above is the database of four integrity constraints, that their specific role is what, of course, they are set and constrained to the data, so this need you to look carefully, especially the relationship between the main foreign key to be particularly clear to the line, Otherwise you will be very difficult to thoroughly understand this database, let us all come to understand understand!!!

PRIMARY KEY Constraints
Teacher's sentence: "A table must be set the primary key, otherwise people will scold you." Let me instantly understand the primary key is so important;
If a table does not set the primary key, to the subsequent learning framework, the framework will bully you, give you an error.
The self-increment column cannot be given a value manually, and this value is automatically given by the system.
non-null constraint: the same meaning
The default value constraint: the same meaning
CHECK constraint : Use expressions to set rules for values in a table
FOREIGN KEY constraint : A column in Table A is a primary key, but in another 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.
( Note: Foreign KEY constraints can only be set in the External key table)

after that! Is our general common sense of the identity column and the general match, although simple, but also need to mind to remember, otherwise the simple will eventually no longer be simple, but may become the heart forever difficult, then we come to familiar with it!

Identity Columns :
A column that uniquely determines the row of data that is unique in the table.
-Application Prerequisites:
01. Must be an int (smallint) type
02. Set at Identity specification: Identity seed, identity increment
(seed value:) identifies seed: from which data begins to grow
(step:) Identity increment: increments of several numbers at a time

wildcard characters:
_: There is only one character
% any of any characters
Like ' (used to modify)

Having said so much, we should pay attention to some common problems;

01. Foreign Key control is not good
02. In SQL Server, string and date type data are enclosed in single quotes, and numeric types are not
03. Each table must have a primary key, the table without the primary key is not possible.
04. Primary key column is not allowed to be empty
05. The use of composite primary keys is not recommended, and the primary key column selection is based on: as simple as possible.
06. If you cannot find a meaningful column as the primary key for the table, add one more column ID as the primary key column for the table.

The Rest is the common sense that might be missed:

database tables, to delete tables that have foreign key relationships, you must first delete the child table (the Foreign key table).

unknowingly already the database management data Sheet Summary almost finished, hope to be able to help you, whether it is you or me, if there is any problem, please say that we go together to solve, my progress journey must not lack of you,

If you think my summary is good, then continue to pay attention to me! My " manipulate data with SQL statements " is about to wind up, if you need, I will not let you wait too long.

Database (SQL Server) Managing database Tables ~ Novelty

Related Article

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.