MySQL-base-1

来源:互联网 发布:淘宝开放平台如何赚钱 编辑:程序博客网 时间:2024/04/29 13:13


    记录一下sql的一些操作

    1. 表操作

//创建数据表$sql = "CREATE TABLE IF NOT EXISTS `$table` (`id` int(10) unsigned NOT NULL auto_increment,`name` varbinary(100) NOT NULL,`datetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,`address` varbinary(30) default NULL,`password` varchar(100) NOT NULL DEFAULT '',PRIMARY KEY  (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ";

    2.  添加列

//向数据库中添加一列,并指定为主键alter table test add new_field int(5) unsigned  not null auto_increment, add primary key(new_field);//alter table test add new_field int(5) unsigned default 1 not null auto_increment, add primary key(new_field); //不能正常执行

    3. 删除列

//删除数据表中id列alter table test drop column id;</span>

    4. /重命名change

/*ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name CHANGE [COLUMN] old_col_name new_col_name column_definition [FIRST|AFTER col_name]*/alter table test change new_field id varchar(1) ;</span>

    5.重命名表
//重命名表名alter table test rename test1;</span>




0 0
原创粉丝点击