本篇內容主要講解“怎么操作數據表”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強。下面就讓小編來(lái)帶大家學(xué)習“MySQL怎么操作數據表”吧!
MySQL操作數據表的方法并不復雜,下面將為您詳細介紹MYSQL添加字段、修改字段、刪除字段、 獲取表名等操作的實(shí)現方法,希望對您學(xué)習MySQL添加字段方面會(huì )有所幫助。
MySQL添加字段的方法并不復雜,下面將為您詳細介紹MYSQL添加字段和修改字段等操作的實(shí)現方法,希望對您學(xué)習MySQL添加字段方面會(huì )有所幫助。
1添加表字段
alter table table1 add transactor varchar(10) not Null; alter table table1 add id int unsigned not Null auto_increment primary key
添加到特定字段后面的語(yǔ)句例子:
ALTER TABLE <表名> ADD <新字段名><數據類(lèi)型>[約束條件]; ALTER TABLE MyTableName ADD newDBField varchar(30) NULL AFTER existDBField; ALTER TABLE tableName001 ADD WebAdminPass varchar(30) NULL AFTER Result;
2.修改某個(gè)表的字段類(lèi)型及指定為空或非空
alter table 表名稱(chēng) change 字段名稱(chēng) 字段名稱(chēng) 字段類(lèi)型 [是否允許非空]; alter table 表名稱(chēng) modify 字段名稱(chēng) 字段類(lèi)型 [是否允許非空]; alter table 表名稱(chēng) modify 字段名稱(chēng) 字段類(lèi)型 [是否允許非空];
3.修改某個(gè)表的字段名稱(chēng)及指定為空或非空
alter table 表名稱(chēng) change 字段原名稱(chēng) 字段新名稱(chēng) 字段類(lèi)型 [是否允許非空
4如果要刪除某一字段,可用命令:
ALTER TABLE mytable DROP 字段名;
mysql SQL獲取表名&字段名的查詢(xún)語(yǔ)句
1:查詢(xún)數據庫中所有表名
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table'; table_schema:數據庫名稱(chēng) information_schema 表示系統庫。 table_type='base table‘:限定只查詢(xún)基表。
2:查詢(xún)指定數據庫中指定表的所有字段名column_name
select column_name from information_schema.columns where table_schema='csdb' and table_name='users'; table_schema:數據庫名 table_name:表名
工作用到例子:
select count(*) from information_schema.columns where table_schema='yanfa' and table_name='tableName001' and column_name='Result1'; #select table_name from information_schema.tables where table_schema='yanfa' and table_type='base table';
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站