当前位置: 首页 > news >正文

sql server笔记

创建数据库

use master
gocreate database stuuuuu//删除数据库if db_id ('$$$') is not nullDrop database [$$$]
go//新建表USE [studyTest]
GOSET ANSI_NULLS ON
GOSET QUOTED_IDENTIFIER ON
GOCREATE TABLE [dbo].[Table_1]([id] [int] NULL,[name] [varchar](10) NULL
) ON [PRIMARY]
GO//删除表
USE [studyTest]
GOIF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Table_1]') AND type in (N'U'))
DROP TABLE [dbo].[Table_1]
GO

插入  insert into aaa ( name ) values ('asd')

/* 更新*/
update aaa set name='我是' where id=1


/* 删除*/
delete aaa where id =1
go

/*条件查询*/
select id as '标识',
        name as '姓名',
        score as 分数
        from aaa where score >20 and score <90 
        /* score >20 and score <90 可以替换成between 50 and 90
            不为空条件  where score is not null*/

/*百分比查询数据*/
select top(50) percent id as '标识',
        name as '姓名',
        score as 分数
        from aaa where score >20 and score <90         

caseWhen判断

select name,score ,case when score >20 and    score<50 then '不及格' 
                        when   score>60 then '好' 
                        else '零'
                        end as '等级'
                    from aaa order by score asc


// in
select name,score from aaa where id in (2)
// like
select name,score from aaa where name like 'a%'

// with
with tt as (select name,score from aaa where name like 'a%')
select * from tt
//distinct
select distinct id from aaa
//order by 升序 asc 降序 desc
select *from aaa order by score asc

//聚合group by
select  name,sum(score) scoresum from aaa group by name

//左连接   left inner right  full join
select *from Company c left join SysUser s on c.Id=s.CompanyId and .....

// union unionall 把结构相同的表合并,union可以去重, unionall 不会去重
 

//递归查询

with  con(id,meanname,parentid,le) as 

 (

               select id,meanname,parentid,le from meaninfo  where id=1

                union all

                select a.id .... , le = le+1 from meaninfo a join con a.parent = con.id

)

 select  id,meanname,parentid,le  from con

数据类型 

date 年月日3byte  datetime 年月日时分秒8byte time 时分秒5byte

约束 

主键约束,外键约束 ,非空约束,唯一约束,检查约束

存储过程

http://www.lryc.cn/news/544015.html

相关文章:

  • AI Video Composer:基于Qwen2.5-Coder的简易开源视频创作利器
  • AI数字人开发,引领科技新潮流
  • VoIP之音频3A技术
  • [原创]openwebui解决searxng通过接口请求不成功问题
  • Jmeter聚合报告导出log文档,Jmeter聚合报告导出到CSV
  • mysqldump 参数详解
  • DeepSeek R1 简易指南:架构、本地部署和硬件要求
  • 基于 ‌MySQL 数据库‌对三级视图(用户视图、DBA视图、内部视图)的详细解释
  • [Web 信息收集] Web 信息收集 — 手动收集 IP 信息
  • 跨AWS账户共享SQS队列以实现消息传递
  • DeepSeek 202502 开源周合集
  • springai系列(二)从0开始搭建和接入azure-openai实现智能问答
  • Apache部署Vue操作手册(SSL部分)
  • 人类驾驶的人脑两种判断模式(反射和预判)-->自动驾驶两种AI模式
  • Docker和K8S中pod、services、container的介绍和关系
  • 【uniapp】在UniApp中实现持久化存储:安卓--生成写入数据为jsontxt
  • DeepSeek-R1本地部署保姆级教程
  • Python常见面试题的详解25
  • DeepSeek赋能大模型内容安全,网易易盾AIGC内容风控解决方案三大升级
  • 阿里开源正式开园文生视频、图生视频模型-通义万相 WanX2.1
  • 【Python爬虫(73)】用Python爬虫开启交通数据宝藏,畅行出行未来
  • 和鲸科技携手四川气象,以 AI 的力量赋能四川气象一体化平台建设
  • spring boot 2.7 + seata +微服务 降级失败问题修复
  • python-leetcode-最长公共子序列
  • centos 7 停更后如何升级kernel版本 —— 筑梦
  • WPF-3天快速WPF入门并达到企业级水准
  • 爬虫反爬:CSS位置偏移反爬案例分析与实战案例
  • Ubuntu20.04安装Redis
  • Ubuntu 22.04 安装Nvidia驱动加速deepseek
  • OkHttp、Retrofit、RxJava:一文讲清楚