zoukankan      html  css  js  c++  java
  • 数据库学习杂项

    纯随笔....

    --查看表的定义 
    sp_help
    exec sp_help 't_users'
     
    --查看表中的数据 
    SELECT * from t_users
     
    --获取有关表的信息 
    SELECT * from sys.tables
     
    --获取有关表列的信息 
    SELECT * from sys.columns where object_id in (SELECT object_id from sys.tables)
    SELECT COLUMNPROPERTY( OBJECT_ID('t_zichan'),N'f_zcid','PRECISION')
    SELECT OBJECT_ID('t_zichan')
    
    --获取有关将要计算的表列的信息 
    SELECT * from sys.computed_columns
     
    --查看表的依赖关系 
    sys.sql_dependencies (Transact-SQL)
    
    --TRUNCATE TABLE 在功能上与没有 WHERE 子句的 DELETE 语句相同 但是TRUNCATE TABLE 速度更快
    --TRUNCATE TABLE t_zichan
    
    --自定义主键id需先identity_insert '主键' on 才可以
    set identity_insert '主键' on
    insert into 表('主键') values('111')
    
    --用户与进程信息
    exec sp_who
    exec sp_who2
    
    --top 50 percent = 50% ,top 2 with ties 最后一条相同的都查出
    select top 50 percent * from t_zichan
    select top 2 with ties * from t_zichan order by f_zcsl desc
    
    --不重复记录
    select distinct f_zczwsl from t_zichan
    
    --标识列和GUID列
    --在SQL Server的表中,可能会有两种特殊的列。一种是标识列(Identity),一种是全球唯一标识符(GUID)
    select @@identity
    select IDENTITYCOL from t_zichan
    select $identity from t_zichan
    select $rowguid from t_zichan
    
    --表join自己
    select *
    from [HongJing_data].[dbo].[t_caidan] a full join [HongJing_data].[dbo].[t_caidan] b on a.f_cdupid = b.f_cdid 
    
    --group by汇总 :with cube,with rollup, all
    select f_zcid,sum(f_zcsl),f_zczwsl from t_zichan
    group by f_zczwsl,f_zcid
    with cube
    
    --compute by归类
    select * from t_zichan compute sum(f_zcsl)
    select * from t_zichan order by f_zcid compute sum(f_zcsl) by f_zcid
    
    --isnull
    select [f_zcid],isnull([f_zcmc],''),[f_zcdw],[f_zcdj],[f_zcsl],[f_zczwsl],[f_zcgmrq],[f_zccgr]
    from t_zichan
    
    --raisserror
    raiserror('ddd',16,5)
    
    --存储过程返回结果集,标量值,影响行数,错误信息
    drop procedure dbo.aaa
    go
    create procedure dbo.aaa
    as
    set nocount off
    
    declare @date date = getdate()
    exec Pro_Insert_Zichan '书籍a','',99.9,50,@date,'采购人1'
    print '影响行数: '+cast(@@rowcount as varchar)
    
    select * from t_zichan
    print '影响行数: '+cast(@@rowcount as varchar)
    return 5
    go
    
    drop procedure dbo.bbb
    go
    create procedure dbo.bbb
    as
    select * from t_zichan
    select * from t_users
    go
    
    declare @re int = 0
    exec @re = aaa
    select @re
    
    --cast 和 convert
    select cast('2001-01-01 10:10:10' as time),CONVERT(date ,'2001-01-01 10:10:10')
    
    --字符串当语句执行(ntext/nchar/nvarchar类型 N'..')
    declare @sql nvarchar(100)
    set @sql = N'select * from t_zichan'
    select @sql
    exec sp_executesql @sql
    exec sp_executesql N'select * from t_zichan'



  • 相关阅读:
    worker与redis网络中断后,worker不再接受任务的异常问题
    Pyecharts 绘制动态流线地图
    MySql存储过程知识了解
    Pyecharts配置项使用
    Pandas一个需求:存在一个列表,需要在一个DataFrame中取到以该列表为索引的数据
    mysql时间与字符串之间相互转换
    map + apply + applymap
    pandas——read_csv
    Python 原生协程------asyncio(选自公众号)
    一道记数题
  • 原文地址:https://www.cnblogs.com/spider024/p/2973589.html
Copyright © 2011-2022 走看看