zoukankan      html  css  js  c++  java
  • SQL添加表字段以及SQL查询表,表的所有字段名

    通用式: 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 column 字段名 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='表名';

  • 相关阅读:
    算法
    UVA 10318 Security Panel(DFS剪枝 + 状压 + 思维)题解
    CodeForces 509C Sums of Digits(贪心乱搞)题解
    UVA 10382 Watering Grass(区间覆盖,贪心)题解
    CodeForces 430A Points and Segments (easy)(构造)题解
    CodeForces 459C Pashmak and Buses(构造)题解
    newcoder F石头剪刀布(DFS + 思维)题解
    newcoder H肥猪(单调队列 / 线段树)题解
    UVALive 7501 Business Cycle(二分)题解
    UVALive 7503 Change(乱搞)题解
  • 原文地址:https://www.cnblogs.com/xuxiaoshuan/p/3990306.html
Copyright © 2011-2022 走看看