mysql修改表結構

來源:互聯網
上載者:User

標籤:類型   localhost   char   oca   value   sel   mit   select   default   

mysql表操作1,//建立表mysql>Create table usertest(id int(12) primary key not null auto_increment,url varchar(34) not null);2,//改表名mysql>Alter  table usertest rename to cmf_usertest;mysql>alter table zm_useroplog  day  date not null default current_date;3,//插資料mysql>Insert into cmf_usertest (downurl) values (‘dfsafa’);4,//增加主鍵mysql>alter table zm_useroplog add id int auto_increment primary key;5,//加索引mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]); 例子: mysql> alter table employee add index emp_name (name);6,//刪除某個索引mysql> alter table 表名 drop index 索引名;7,加唯一限制條件的索引mysql> alter table 表名 add unique 索引名 (欄位名);8, 增加欄位mysql> ALTER TABLE table_name ADD field_name field_type; 9, 修改原欄位名稱及類型mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type; 10, 刪除欄位MySQL ALTER TABLE table_name DROP field_name; 11,修改一個欄位mysql> alter table user MODIFY new1 VARCHAR(10);  //修改一個欄位的類型mysql> alter table user CHANGE new1 new4 int;  //修改一個欄位的名稱,此時一定要重新指定該欄位的類型12,匯出表,設定編碼,限制條數。mysqldump --default-character-set=latin1 -u root -h localhost -ppassword db_name tab_name  --where="true limit 10" >> tab_name.sql13,查詢時間戳記顯示時間mysql> select from_unixtime(a.ptime,‘%Y-%m-%d‘) as pdate , a.col as a_cal, b.cal as b_cal  from tab1_name a left join tab2_name b on a.id = b.id group by a_col , b_col ;14,插入目前時間now()函數以`yyyy-mm-dd hh:mm:ss返回當前的日期時間,可以直接存到datetime欄位中。curdate()以’yyyy-mm-dd’的格式返回今天的日期,可以直接存到date欄位中。curtime()以’hh:mm:ss’的格式返回當前的時間,可以直接存到time欄位中。 

mysql修改表結構

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.