使用关键字作为字段名称

2017-07-18 • • 暂无评论

在Oracle 中只能用双引号"包围关键字。但由于Oracle中双引号内的字符串是区分大小写的,而不管创建表还是查询时,Oracle都会把字段名转成全部大写,所以,除非创建表时双引号内的字段名就是全大写的,否则以后查询时SQL语句都必须加双引号,若不加则Oracle内部会把字段名转成全大写从而提示“无效的标识符”。同理,查询普通字段也可以通过加双引号查询得出,但双引号内的字段名必须是全大写,例如SELECT "ANY_FIELD_NAME" FROM TableName
在SQL Server 中可以用方括号[]或双引号"包围关键字。字段名任何情况下都不区分大小写。
在MySQL 中用`(backticks)把表和列名名字围起来。字段名也不区分大小写。
在Hibernate 中必须在定义映射关系时用backticks(`)包围字段名,具体参考这里 或这里 。

清理SqlServer2008 R2的数据库日志

2017-07-15 • • 暂无评论

USE [master]
    GO
    ALTER DATABASE DbName SET RECOVERY SIMPLE WITH NO_WAIT
    GO
    ALTER DATABASE DbName SET RECOVERY SIMPLE   --简单模式
    GO
    USE wenzhou_dc 
    GO
    DBCC SHRINKFILE (N'wenzhou_dc_Log' , 11, TRUNCATEONLY)
    GO
    USE[master]
    GO

    ALTER DATABASE DbName SET RECOVERY FULL WITH NO_WAIT

    GO

    ALTER DATABASE DbName SET RECOVERY FULL  --还原为完全模式

    GO

SqlServer 获取数据库全部字段

2017-07-14 • • 暂无评论

Select o.Name As ObjectsName , c.name As ColumnsName , t.name As ColumnsType , c.length As ColumnsLength
From SysObjects As o , SysColumns As c , SysTypes As t
Where o.type in ('u','v') And o.id = c.id And c.xtype = t.xtype
Order By o.name , c.name , t.name , c.Length

获取字段的元数据

2017-07-13 • • 暂无评论

SELECT
    表名=case   when   a.colorder=1   then   d.name   else   ''   end,
    表说明=case   when   a.colorder=1   then   isnull(f.value,'')   else   ''   end,
    字段序号=a.colorder,
    字段名=a.name,
    标识=case   when   COLUMNPROPERTY(   a.id,a.name,'IsIdentity')=1   then   '√'else   ''   end,
    主键=case   when   exists(SELECT   1   FROM   sysobjects   where   xtype='PK'   and   name   in   (
        SELECT   name   FROM   sysindexes   WHERE   indid   in(
            SELECT   indid   FROM   sysindexkeys   WHERE   id   =   a.id   AND   colid=a.colid
        )))   then   '√'   else   ''   end,
    类型=b.name,
    占用字节数=a.length,
    长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
    小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
    允许空=case   when   a.isnullable=1   then   '√'else   ''   end,
    默认值=isnull(e.text,''),
    字段说明=isnull(g.[value],'')
FROM   syscolumns   a
    left join   systypes   b   on   a.xusertype=b.xusertype
    inner join   sysobjects   d   on   a.id=d.id     and   d.xtype='U'   and     d.name<>'dtproperties'
    left join   syscomments   e   on   a.cdefault=e.id
    left join   sys.extended_properties   g   on   a.id=g.major_id   and   a.colid=g.minor_id
    left join   sys.extended_properties   f   on   d.id=f.major_id   and   f.minor_id=0
where d.name='T_B_POMS_COMPANY'         --如果只查询指定表,加上此条件
order by a.id,a.colorder

Linux更改root密码

2017-07-03 • • 暂无评论

 sudo passwd root