Login Registration Database Setup

Source: Internet
Author: User

Learning the front-end when Ajax learning the main practice is to explain the login registration problem, from the beginning of the source code to the later jquery and then to the back of the Angularjs. The three types of login registration issues are discussed.

I first talk about the establishment of the background database, because no matter what kind of backstage are the same, only the foreground JS when there is a difference.

To log in and register, the first to establish a database, we design the database table must first consider what the database table needs, we give the table named user, the user table first to include Users table ID, this column is set as the primary key of this table, in order to improve the efficiency of the query we need to set a primary key to the table. So even if the names are duplicated, we can also find what we need to find, depending on the primary key, because the primary key cannot be duplicated. Of course, we designed this login registration function will first determine whether the user name exists, if the user name exists can not register, you need to re-enter a user name. The primary key is designed so we give the primary key a name ID, in SQL Server, the primary key is a constraint in a table. This constraint, a table can only have one, generally used as an ID, this constraint is generally given to others foreign key reference. The function of this constraint is that it is not repeatable and guarantees uniqueness, and it is this feature that allows most people to use him as a field in the ID of the table.

User to log in we need to design a login name, name name, in the name of the time we try to use English words to name, so in the post-SQL statement is easy to read, you can see the name to know what is probably. To login of course there is a few is the user password, usually everyone in a variety of web platforms and QQ and other software is generally required to use the user name and password to log in.

But when you sign up, email and gender sex.

The specific table is designed as follows:

 create table User (id  int  (10 ) not null  auto_increment primary key,  primary key is not empty self-growing  */  name varchar ( 20 ) not null  , pass varchar ( 20 ) not null  , email varchar ( 20 ) not null  Span style= "color: #000000;" >, sex varchar ( 5 ) not null  ) charset  =utf8; 

We can see in the table above that we used varchar instead of char, let me briefly explain the difference between char and varchar, and what is the case with a char when using varchar.

I. Data storage overhead

1.char (n) is fixed-length, that is, when you enter a character less than the number you specify, char (8), the character you enter is less than 8 o'clock, it will be followed by the empty value. When you enter a character that is larger than the specified number, it intercepts the characters that are out of the bounds.

In the program, will return to you 8 bits, the back of the space to fill up;

In the database, char (8), occupies 16 bytes (1 characters = 2 bytes);

2.varchar (n) is a variable-length, non-Unicode character data with a length of n bytes. n must be a numeric value between 1 and 8000. Storage size is the actual length of bytes of input data, not n bytes. The input data character length can be zero.

Two. Inserting data

The null value of the 1.char column occupies storage space.

2. The null value of the varchar column does not occupy storage space.

Inserting the same number of NULL values, the varchar column is significantly more efficient than the Char column.

When inserting non-null data, the efficiency of the varchar column is significantly higher than the Char column, regardless of whether the column involved in inserting the data is indexed.

Three. Updating data

If an index is not indexed on the updated column, char is less efficient than varchar, but the efficiency difference is small.

If an index is established on an updated column, char is less efficient than varchar, and the efficiency varies greatly.

Four. Modify the structure

Regardless of whether the type of columns that are added or deleted is char or varchar, the operation can be done faster and with no difference in efficiency.

There is a significant efficiency difference between char and varchar for increasing the width of the column, and the varchar column does not take much time, and it takes a long time to modify the Char column.

Five. Data retrieval

The data retrieval of the varchar type is slightly better than the scan of char, regardless of whether it is indexed.

What kind of application do we use in the actual development?

Char is used when determining the length of a string, data changes frequently, and data retrieval requirements;

VarChar is used when you are unsure of the length of the string, few changes to the data, and frequent queries.

As shown, we can see that the table is built as follows:

The table is built and we need to write the SQL statement.

First, if we log in without an account to register, registration is to add data to the database table, I first write a simple example of adding data;

If the user name is Susan1, the password is 123456, email [email protected], sex female

The statements are as follows:

Insert into User (Name,pass,email,sex) VALUES ("Susan1", 123456, "[email protected]", "female");

  

You can look at the table data already added, as shown in:

We want to register the time to enter the user name to see if the user name exists, the idea is as follows:

SELECT * from user where u_name= "+name+"; " +name+ "means the name of the input, the first query table inside the user name is equal to the input name, if not the data length is zero, it can be registered with the name, if the length is greater than 0 is the user name exists, you need to re-enter the user name registration.

Of course there is a need to make the deletion of the user's function, delete the user example is as follows, for example, I want to delete the user name is Zhang San user, you can write:

Delete from  where u_name="susan1";

The user name in the form is susan1 and has been deleted.

We ask for all the users to print out, if the database has a lot of user names, we also need to do the user paging. User paging can have two methods, one is to query out all the users and then in the foreground to page, so the workload is relatively large, we use the second, assume that a page load five items, that is, the first page load query data first five items, the second page to find the 6th to tenth.

The SQL statements are as follows:

Select  from 5; /* first Page */

The query results are as follows:

Select  from 5,5; /* second page */

The query results are as follows:

It is important to note that when we query from the first few items are calculated from 0.

Login Registration Database Setup

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.