Little white MySQL Note (i)

Source: Internet
Author: User

The content from StackOverflow is mostly.

1-mysql VARCHAR size?

2-Database design paradigm

3-what is and in InnoDB MyISAM MySQL ?

4- Why handwriting DDL?

5-data Access Object (DAO) in Java

MySQL VARCHAR size?

Q:

I ' m wondering, if I have a VARCHAR of $ characters and that I put a string of the characters, would it use the bytes or I T would just use the actual size of the string?

A:

Characters.

This is the var (variable) in: You are only varchar store, and an extra 2 bytes to store length upto 655 35)

If It is then your char(200) ' d always store characters, padded with spaces

See the docs: "The CHAR and VARCHAR Types" -------by gbn

Add:

varchar (M) is a more flexible data type than char and is also used to represent character data, but varchar can hold variable-length strings. where m represents the maximum length of a string that is allowed to be saved by the data type, as long as a string that is less than the maximum value can be saved in that data type. Therefore, it is wiser to use the varchar data type for data objects that are difficult to estimate the exact length. MySQL4.1 previously, the varchar data type supported a maximum length of 255, 5.0 or more versions supported 65535 byte lengths, and a maximum of 21,843 characters (not empty) under UTF8 encoding ------from Baidu Encyclopedia

Database design Paradigm

How can we design a good database?  After years of research, experts finally Generally in accordance with the paradigm of database design to get a good database, the purpose of the paradigm is: to eliminate data redundancy and programming convenience.

The first paradigm is to get a pure two-dimensional table, //Only a pure two-dimensional table can be loaded into the database

The second paradigm is the elimination of non-primary key dependencies, //"Some columns do not directly depend on the primary key", meaning that things that matter to the primary key should be thrown into another table.

The third paradigm is to eliminate the function dependency relationship. //Can be calculated not to take an additional list of installed ...

The main way to do the paradigm is to "split the table", but it has side effects, and so on, so in the data redundancy and coding easy to find a balance between, to the third paradigm, basically is the balance point. ------"Java is the way to learn"

What are and in InnoDB MyISAM MySQL ?

InnoDBMYISAMand, is storage engines for MySQL .

These differ on their locking implementation: InnoDB locks the particular row in the table, and MyISAM locks the Entir e MySQL table.

You can specify the type by giving MYISAM OR while InnoDB creating a table in DB. ------by Siva

Why handwriting DDL ( Data Definition Language )?

Schema.sql (demo):

--Database Initialization Script--Create a databaseCREATE DATABASEchat;--Working with Databases Usechat;--Create a tableCREATE TABLE User(  user_id BIGINT  not NULLAuto_increment COMMENT'User ID', usernameVARCHAR( +) not NULLCOMMENT'User name (email)', PasswordVARCHAR( +) not NULLCOMMENT'Password', nicknameVARCHAR( -) not NULLCOMMENT'Nickname', OtherVARCHAR( -) COMMENT'other',  PRIMARY KEY(user_id) ) ENGINE=InnoDB auto_increment= + DEFAULTCHARSET=UTF8 COMMENT='User basic Information';CREATE TABLEFriend_relation (user_id BIGINT  not NULLCOMMENT'User ID', friend_idBIGINT  not NULLCOMMENT'Friend ID') ENGINE=InnoDBDEFAULTCHARSET=UTF8 COMMENT='Friend Relationship Table';CREATE TABLEGroup_relation (user_id BIGINT  not NULLCOMMENT'User ID',, group_idBIGINT  not NULLCOMMENT'Group ID') ENGINE=InnoDBDEFAULTCHARSET=UTF8 COMMENT='Group Relationship Table';--Initializing DataINSERT  into  'User'('username','Password','Nickname',' Other')VALUES  ('[email protected]',123456,'boss','This guy's lazy, he didn't write anything.'),  ('[email protected]',123456,'Dick','Flat light is true');--INSERT into--' friend_relation ' (' user_id ', ' friend_id ')--VALUES-- Why handwriting DDL (Data Definition Language)--record DDL modifications on-line, v 1.1--xxx--on-line v 1.2--xxx x x

MySQL If the table exists, delete it:

 DROPTABLEIFEXISTS  tbl_name;

Data Access Object (DAO) in Java

Q:

I was going through a document and I came across a term called DAO . I found out the It is a Data Access Object. Can someone explain me what's this actually is?

I know that it is some kind of a interface for accessing data from different types of sources, in the middle of this Litt Le mine I bumped into a concept called data source or data source object, and things got messed on my mind.

I really want to know-A is programmatically in terms of the DAO where it is used. How is it used? Any links to pages of explain this concept from the very basic stuff are also appreciated. ------by vasanth Nag K V

A:

The Data access Object is basically a object or an interface this provides Access to a underlying database or any other Persistence storage.

That definition From:http://en.wikipedia.org/wiki/data_access_object

Check also the sequence diagram here:http://www.oracle.com/technetwork/java/dataaccessobject-138824.html

Maybe a simple example can help you understand the concept:

Let's say we have a entity to represent an employee:

 Public classEmployee {Private intID; PrivateString name;  Public intgetId () {returnID; }     Public voidSetId (intID) { This. ID =ID; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }}

The employee entities'll be persisted to a corresponding Employee table in a database. A simple DAO interface to handle the database operation required to manipulate an employee entity would be like:

Interface EmployeeDAO {    List<Employee> findAll ();    List<Employee> FindByID ();    List<Employee> findbyname ();     Boolean Insertemployee (employee employee);     Boolean UpdateEmployee (employee employee);     Boolean Deleteemployee (employee employee);}

Next we have to provide a concrete implementation for the interface to deal with SQL server, and another to deal with FLA t files, etc. ------by Rami

Little white MySQL Note (i)

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.