免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1428 | 回复: 0
打印 上一主题 下一主题

Alter 语句的使用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-25 14:14 |只看该作者 |倒序浏览
Table Manipulation
Lets say you made your table, and all the data has been
    added to it. Now you have come across a problem... your
    limit for characters in that particular column is too small
    for what you now need. You don't want to have to delete all
    of this data, yet, you have to change your table some how.
Fret no more everyone, you can manipulate your tables that
      have already been created.
The command for this task is known as ALTER TABLE. Just a
        note, it is possible to mix and match these commands,
        usually just separate them with a comma (,), or just place
        them all in the same line. Play around with them to get a
feel for what I am talking about.
Renaming a Table
mysql> ALTER TABLE users RENAME public;
Changing a columns datatype
mysql> ALTER TABLE public MODIFY name CHAR(150);
Renaming a Table and Changing its datatype at once
mysql> ALTER table users CHANGE
-> email emailaddy CHAR (100);
Adding a Column
mysql> ALTER TABLE public ADD time TIMESTAMP;
Remove a Column
mysql> ALTER TABLE public DROP COLUMN time;  
After you make these changes to the table, you may want to
                            optimize the table afterwards (especially if you are using
                            VARCHAR's, TEXT's or BLOB's, as this will optimize its
                            memory allocation. You will also want to do it if you have
                            deleted a large part of a table.
During a table optimization, the original table is available
                              to clients, however, modifying and adding to the table is
                              stalled until optimization is complete.
The syntax is:
OPTIMIZE TABLE table_name_goes_here
Deleting an entire table
To delete (or drop) an entire table, you would use the
following syntax;
mysql> DROP TABLE public;  
If you would like to drop more tables at once though, you
  would do this;
mysql> DROP TABLE public, tests;  
Though this does not even remotely cover all of the available
features found within MySQL, it does scratch the surface enough to
catch your interest. Look for more tutorials coming soon on
TheScripts.com covering MySQL's features.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/73684/showart_1221298.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP