您的位置:首页 > 博客中心 > 数据库 >

SQL添加表字段以及SQL查询表,表的所有字段名

时间:2022-03-14 00:12

通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: alter table [表名] add 字段名 smallint default 0 增加数字字段,整型,缺省值为0  alter table [表名] add 字段名 int default 0 增加数字字段,长整型,缺省值为0 alter table [表名] add 字段名 single default 0 增加数字字段,单精度型,缺省值为0  alter table [表名] add 字段名 double default 0 增加数字字段,双精度型,缺省值为0 alter table [表名] add 字段名 Tinyint default 0 增加数字字段,字节型,缺省值为0   alter table [表名] add 字段名 text [null] 增加备注型字段,[null]可选参数 alter table [表名] add 字段名 memo [null] 增加备注型字段,[null]可选参数   alter table [表名] add 字段名 varchar(N) [null] 增加变长文本型字段 大小 为N(1~255) alter table [表名] add 字段名 char [null] 增加定长文本型字段 大小固定为255   alter table [表名] add 字段名 Datetime default 函数 增加日期型字段,其中 函数 可以是 now(),date()等,表示缺省值 (上面都是最常用的,还有其他的属性,可以参考下面的数据类型描述)   删除字段: alter table [表名] drop 字段名   修改变长文本型字段的大小:alter table [表名] alter 字段名 varchar(N)   删除表: drop table [表名]      

SQL查询表,表的所有字段名

SQL SERVER

查看所有表名:
select name from sysobjects where type=‘U‘

查询表的所有字段名:
Select name from syscolumns Where ID=OBJECT_ID(‘表名‘)

select * from information_schema.tables
select * from information_schema.views
select * from information_schema.columns

ACCESS


查看所有表名:
select name from MSysObjects where type=1 and flags=0

MSysObjects是系统对象,默认情况是隐藏的。通过工具、选项、视图、显示、系统对象可以使之显示出来。

Oracle
select cname from col where tname=‘ZW_YINGYEZ‘

select column_name from user_tab_columns where table_name=‘ZW_YINGYEZ‘

查询表字段数
select count(column_name) from user_tab_columns where table_name=‘表名‘;

本类排行

今日推荐

热门手游