这篇文章给大家分享的是MySQL中怎样进行表操作的内容,下文会介绍MYSQL添加字段、修改字段、删除字段、 获取表名等操作及方法,小编觉得挺实用的,因此分享给大家做个参考,文中示例SQL语句介绍的非常详细,感兴趣的朋友接下来一起跟随小编看看吧。
MySQL添加字段的方法并不复杂,下面将为您详细介绍MYSQL添加字段和修改字段等操作的实现方法,希望对您学习MySQL添加字段方面会有所帮助。
1添加表字段
alter table table1 add transactor varchar(10) not Null; alter table table1 add id int unsigned not Null auto_increment primary key
添加到特定字段后面的语句例子:
ALTER TABLE <表名> ADD <新字段名><数据类型>[约束条件]; ALTER TABLE MyTableName ADD newDBField varchar(30) NULL AFTER existDBField; ALTER TABLE tableName001 ADD WebAdminPass varchar(30) NULL AFTER Result;
2.修改某个表的字段类型及指定为空或非空
alter table 表名称 change 字段名称 字段名称 字段类型 [是否允许非空]; alter table 表名称 modify 字段名称 字段类型 [是否允许非空]; alter table 表名称 modify 字段名称 字段类型 [是否允许非空];
3.修改某个表的字段名称及指定为空或非空
alter table 表名称 change 字段原名称 字段新名称 字段类型 [是否允许非空
4如果要删除某一字段,可用命令:
ALTER TABLE mytable DROP 字段名;
mysql SQL获取表名&字段名的查询语句
1:查询数据库中所有表名
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table'; table_schema:数据库名称 information_schema 表示系统库。 table_type='base table‘:限定只查询基表。
2:查询指定数据库中指定表的所有字段名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';
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。