关于mysql的聚集索引
翻译:
InnoDB表会包含一个聚集索引(数据表的物理存储顺序和表的逻辑存储顺序一致)
一般是按照下面的规则来设定聚集索引的:
1,假如表包含PRIMARY KEY,InnoDB使用它作为聚集索引
2,假如表没有定义PRIMARY KEY,InnoDB将第一个只包含NOT NULL属性列的UNIQUE index作为主键并且将它设置为聚集索引
3,前两者都不满足的时候,mysql就增加一个隐藏的autocreament
Every InnoDB
table has a special index called
the clustered index
where the data for
the rows is stored:
If you define a PRIMARY KEY
on your
table, InnoDB
uses it as the clustered
index.
If you do not define a PRIMARY KEY
for
your table, MySQL picks the first UNIQUE
index that has only NOT NULL
columns as
the primary key and InnoDB
uses it as the
clustered index.
If the table has no PRIMARY KEY
or
suitable UNIQUE
index,
InnoDB
internally generates a hidden
clustered index on a synthetic column containing row ID
values. The rows are ordered by the ID that
InnoDB
assigns to the rows in such a
table. The row ID is a 6-byte field that increases
monotonically as new rows are inserted. Thus, the rows
ordered by the row ID are physically in insertion order.
Accessing a row through the clustered index is fast because the
row data is on the same page where the index search leads. If a
table is large, the clustered index architecture often saves a
disk I/O operation when compared to storage organizations that
store row data using a different page from the index record.
(For example, MyISAM
uses one file for data
rows and another for index records.)
In InnoDB
, the records in nonclustered
indexes (also called secondary indexes) contain the primary ke
相关文档:
1、提交表单Javascript验证
<form action="" method="post" name="myform" onsubmit="return CheckPost();">
SCRIPT language=javascript>
function CheckPost()
{
if (myform.user.value=="")
{
alert("请填写用户");
myform.user.focus();
return f ......
//主键
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新列
alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
//删除列
alter table t2 drop column c;
//重命名列
......
START TRANSACTION, COMMIT和ROLLBACK语法
START TRANSACTION | BEGIN [WORK]
COMMIT [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
ROLLBACK [WORK] [AND [NO] CHAIN] [[NO] RELEASE]
SET AUTOCOMMIT = {0 | 1}
START
TRANSACTION或BEGIN语句可以开始一项新的事务。COMMIT可以提交当前事务,是变更成为永久变更。ROLLBACK ......
MySQL可以为不同的用户分配严格的、复杂的权限。这些操作大多都可以用SQL指令Grant(分配权限)和Revoke(回收权限)来实现。 Grant可以把指定的权限分配给特定的用户,如果这个用户不存在,则会创建一个用户。
Grant 常用格式:
grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 ide ......