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='表名';

  • 相关阅读:
    1-1 课程简介 & 2-1 IDEA与Eclipse的不同 & 2-3 Intellij IDEA安装
    MyBatis入门
    贪婪法——————贪心算法
    Java排序之直接选择排序
    是时候学一波STL了。。。
    Java提高篇(三一)-----Stack
    Android 经常使用工作命令mmm,mm,m,croot,cgrep,jgrep,resgrep,godir
    【POJ 2750】 Potted Flower(线段树套dp)
    POJ 题目3321 Apple Tree(线段树)
    Android新手入门2016(14)--FragmentTabHost实现选项卡和菜单
  • 原文地址:https://www.cnblogs.com/xuxiaoshuan/p/3990306.html
Copyright © 2011-2022 走看看