MySQL數據庫教程,mysql筆記手寫_MySQL 筆記(一)

 2023-10-02 阅读 29 评论 0

摘要:VARCHAR(M)是一種比CHAR更加靈活的數據類型,同樣用于表示字符數據,但是VARCHAR可以保存可變長度的字符串。其中M代表該數據類型所允許保存的字符串的最大長度,只要長度小于該最大值的字符串都可以被保存在該數據類型中。因此,對于那些難以估計確切

VARCHAR(M)是一種比CHAR更加靈活的數據類型,同樣用于表示字符數據,但是VARCHAR可以保存可變長度的字符串。其中M代表該數據類型所允許保存的字符串的最大長度,只要長度小于該最大值的字符串都可以被保存在該數據類型中。因此,對于那些難以估計確切長度的數據對象來說,使用VARCHAR數據類型更加明智。MySQL4.1以前,VARCHAR數據類型所支持的最大長度255,5.0以上版本支持65535字節長度,utf8編碼下最多支持21843個字符(不為空) ?------ 來自百度百科

數據庫設計范式

MySQL數據庫教程?如何能設計出優秀的數據庫呢?專家們經過多年研究終于····· ?一般按照范式來進行數據庫設計就得到良好的數據庫,范式的目的在于:消除數據冗余和編程便利。

第一范式就是得到純二維表,// 只有純二維的表才能裝進數據庫

第二范式是消除非主鍵依賴關系,// “有些列并不直接依賴于主鍵”,就是說和主鍵沒關系的東西應該扔到另外一張表中去。

MySQL實例?第三范式是消除函數依賴關系。// 能算出來的就別額外拿一列裝了。。。

做范式的主要手段是“拆表”,但是要它有副作用,······,所以要在數據冗余和編碼容易之間尋找平衡點,到了第三范式,基本上就是平衡點了。 ?------ 《 Java 就該這樣學》

What is?InnoDB?and?MyISAM?in?MySQL??

mysql基礎知識筆記,InnoDB?and?MYISAM, are storage engines for?MySQL.

These two differ on their locking implementation:?InnoDB?locks the particular row in the table, and?MyISAM?locks the entire?MySQL?table.

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

為什么手寫 DDL (Data Definition Language)?

schema.sql(demo):

--數據庫初始化腳本

--創建數據庫

CREATE DATABASEchat;--使用數據庫

usechat;--創建表

CREATE TABLE user(user_id BIGINT NOT NULL AUTO_INCREMENT COMMENT '用戶id',

usernameVARCHAR(40) NOT NULL COMMENT '用戶名(郵箱)',

passwordVARCHAR(40) NOT NULL COMMENT '密碼',

nicknameVARCHAR(20) NOT NULL COMMENT '昵稱',

otherVARCHAR(120) COMMENT '其他',PRIMARY KEY (user_id)

)ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 COMMENT='用戶基本信息';CREATE TABLEfriend_relation(user_id BIGINT NOT NULL COMMENT '用戶id',

friend_idBIGINT NOT NULL COMMENT '好友id')ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='好友關系表';CREATE TABLEgroup_relation(user_id BIGINT NOT NULL COMMENT '用戶id',,

group_idBIGINT NOT NULL COMMENT '群組id')ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='群組關系表';--初始化數據

INSERT INTO

'user'('username', 'password', 'nickname', 'other')VALUES('11122@gmail.com', 123456, '老大', '這人很懶,啥也沒寫'),

('jhgm49@163.com', 123456, '老二', '平平淡淡才是真');--INSERT INTO--'friend_relation'('user_id', 'friend_id')--VALUES

-- 為什么手寫 DDL ( Data Definition Language )

-- 記錄每次上線的 DDL 修改

-- 上線 V 1.1

-- xxx

-- 上線 V 1.2

-- xxx x x

MySQL 如果表存在就刪掉:

DROP TABLE IF EXISTS 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 that it is a Data Access Object. Can someone please explain me what this actually is?

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

I really want to know what a?DAO?is programmatically in terms of where it is used. How it is used? Any links to pages that explain this concept from the very basic stuff is also appreciated.

A:

The Data Access Object is basically an object or an interface that provides access to an underlying database or any other persistence storage.

Maybe a simple example can help you understand the concept:

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

public classEmployee {private intid;privateString name;public intgetId() {returnid;

}public void setId(intid) {this.id =id;

}publicString getName() {returnname;

}public voidsetName(String name) {this.name =name;

}

}

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

interfaceEmployeeDAO {

ListfindAll();

ListfindById();

ListfindByName();booleaninsertEmployee(Employee employee);booleanupdateEmployee(Employee employee);booleandeleteEmployee(Employee employee);

}

Next we have to provide a concrete implementation for that interface to deal with SQL server, and another to deal with flat files, etc. ------ by?Rami

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/110650.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息