mysql常用语句

来源:互联网 发布:终端医院数据库 编辑:程序博客网 时间:2024/06/06 02:20

修改表:

添加字段:alter table yyh_yp_managerrob add catid  smallint(5)
 , add typeid  smallint(5)
, add areaid  smallint(5)
, add title char(150)
, add style char(5)
, add thumb char(100)
, add keywords char(40)
, add description char(255)
, add posids tinyint(1)
, add url char(100)
, add listorder tinyint(3)
, add status tinyint(2)
, add userid mediumint(8)
, add username char(20)
, add inputtime int(10)
, add updatetime int(10)
, add searchid mediumint(8)
, add islink tinyint(1)
, add prefix char(20);

复制表结构:create table newtable (select * from oldtable)

还原数据库:

先删除掉原有的数据库:drop database 数据库名称
然后创建数据库:creat database 数据库名称
然后:use 数据库名称
然后:source .sql文件的路径


补充:

MySQL添加字段的方法并不复杂,下面将为您详细介绍MySQL添加字段和修改字段等操作的实现方法,希望对您学习MySQL添加字段方面会有所帮助。

1.登录数据库
>mysql -u root -p 数据库名称

2.查询所有数据表
>show tables;

3.查询表的字段信息
>desc 表名称;

4.1添加表字段

alter table table1 add transactor varchar(10) not Null;

alter table   table1 add id int unsigned not Null auto_increment primary key

4.2.修改某个表的字段类型及指定为空或非空
>alter table 表名称 change 字段名称 字段名称 字段类型 [是否允许非空];
>alter table 表名称 modify 字段名称 字段类型 [是否允许非空];

>alter table 表名称 modify 字段名称 字段类型 [是否允许非空];

4.3.修改某个表的字段名称及指定为空或非空
>alter table 表名称 change 字段原名称 字段新名称 字段类型 [是否允许非空

4.4如果要删除某一字段,可用命令:ALTER TABLE mytable DROP 字段 名;

修改数据库用户密码命令:

mysql> set password for 'root'@'localhost'=password('miao');
出现Query OK, 0 rows affected (0.00 sec) 则为修改成功。
原创粉丝点击