alter table 表名 modify 你需要的修改的字段。例:
alter table A modify title varchar(25) not null default ''
使用mysql_fetch_field以下是例子.
mysql_fetch_field() 可以用来从某个查询结果中取得字段的信息。如果没有指定字段偏移量,则下一个尚未被 mysql_fetch_field() 取得的字段被提取。
对象的属性为:
name - 列名
table - 该列所在的表名
max_length - 该列最大长度
not_null - 1,如果该列不能为 NULL
primary_key - 1,如果该列是 primary key
unique_key - 1,如果该列是 unique key
multiple_key - 1,如果该列是 non-unique key
numeric - 1,如果该列是 numeric
blob - 1,如果该列是 BLOB
type - 该列的类型
unsigned - 1,如果该列是无符号数
zerofill - 1,如果该列是 zero-filled
=========
<?php
mysql_connect('localhost:3306', $user, $password)
or die("Could not connect: " . mysql_error())
mysql_select_db("database")
$result = mysql_query("select * from table")
or die("Query failed: " . mysql_error())
/* get column metadata */
$i = 0
while ($i <mysql_num_fields($result)) {
echo "Information for column $i:<br />\n"
$meta = mysql_fetch_field($result)
if (!$meta) {
echo "No information available<br />\n"
}
echo "<pre>
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
name: $meta->name
not_null: $meta->not_null
numeric: $meta->numeric
primary_key: $meta->primary_key
table:$meta->table
type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
</pre>"
$i++
}
mysql_free_result($result)
?>
explain显示了mysql如何使用索引来处理select语句以及连接表。可以帮助选择更好的索引和写出更优化的查询语句。使用方法,在select语句前加上explain就可以了,如:
explain
select
*
from
statuses_status
where
id=11
explain列的解释
table:显示这一行的数据是关于哪张表的
type:这是重要的列,显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、indexhe和all
possible_keys:显示可能应用在这张表中的索引。如果为空,没有可能的索引。可以为相关的域从where语句中选择一个合适的语句
key:
实际使用的索引。如果为null,则没有使用索引。很少的情况下,mysql会选择优化不足的索引。这种情况下,可以在select语句中使用use
index(indexname)来强制使用一个索引或者用ignore
index(indexname)来强制mysql忽略索引
key_len:使用的索引的长度。在不损失精确性的情况下,长度越短越好
ref:显示索引的哪一列被使用了,如果可能的话,是一个常数
rows:mysql认为必须检查的用来返回请求数据的行数
extra:关于mysql如何解析查询的额外信息。将在表4.3中讨论,但这里可以看到的坏的例子是using
temporary和using
filesort,意思mysql根本不能使用索引,结果是检索会很慢
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)