易截截图软件、单文件、免安装、纯绿色、仅160KB

Mysql修改表字段

#新增一个字段,默认值为0,非空,自动增长,主键  
 
   alter table tabelname add new_field_name field_type default 0 not null auto_increment ,add primary key (new_field_name);  
 
#增加一个新字段  
 
   alter table tableName add new_field_name field_type;  
   alter table tableName add new_field_name field_type not null default '0';  
 
#删除字段  
 
   alter table tableName drop column field_name;  
 
#重命名字段  
 
   alter table tableName change old_field_name new_field_name new_field_type;  
 
#改变字段的类型  
 
   alter table tableName change field_name field_name field_type;
#改变字段顺序
  alter table emp modify age int(3) first;
   
    alter table emp modify age int(3) after name;
 
   alter table users change user_group user_group VARCHAR( 10 )  after name ;
   
      //如果要提前就把原字段删除,再用first或after属性改
    现在数据库中有没有数据,如果没有数据可以这样做:  
  1。把该字段删除  
        alter   table   your_tablename   drop   电话号码  
  2。在添加该字段  
        alter   table   your_tablename   add   电话号码   first  
        如果该字段不为空且为主键  
        alter   table   your_tablename   add   电话号码   not   null   primary   key   first  
     


相关文档:

MYSQL数据库设计注意事项 数据库优化

现在大概列出如下:
1.数据库的设计
尽量把数据库设计的更小的占磁盘空间.
1).尽可能使用更小的整数类型.(mediumint就比int更合适).
2).尽可能的定义字段为not null,除非这个字段需要null.
3).如果没有用到变长字段的话比如varchar,那就采用固定大小的纪录格式比如char.
4).表的主索引应该尽可能的短.这样的话每条纪录 ......

MySQL常用指令集合


记了一些用 Windows 的命令行来操作 MySQL 的指令。
摘要
连结 MySQL
->mysql -u username -p
username 是你的帐号名称。
远程连结
->mysql -h hostname -u username -p
hostname 是 MySQL 主机的名称。
显示全部的数据库
SHOW DATABASES;
mysql 是 MySQL 用来储存帐号和权限的数据库,不能删除。
选择 ......

mysql 导入、导出数据库、表

mysql 导出表:
mysqldump -u 用户名 -p  --opt  数据库用户名 表名
> 表名.sql
mysql 导出数据库:
mysqldump -u
用户名 -p  --opt  数据库用户名
>
数据库
名.sql
mysql 导入表:
>source e:\base\pet.sql;
mysql 导入表数据:
>LOAD DATA LOCAL INFILE 'e:path/pet.txt ......

MySQL行锁深入研究

     
做项目时由于业务逻辑的需要,必须对数据表的一行或多行加入行锁,举个最简单的例子,图书借阅系统。假设
id=1
的这本书库存为
1
,但是有
2
个人同时来借这本书,此处的逻辑为
Select restnum from book where id =1 ;
-- 如果 restnum 大于 0 ,执行 update
Update boo ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号