zoukankan      html  css  js  c++  java
  • 数据库

    命名习惯 数据库名.MyDB           表名.StuInfo

    数据类型

    int 整形

    datetime 日期    getdate()

    float 浮点

    bit 布尔值

    nvarchar(50) 变长  文本型

    nvarchar(MAX) 备注

    创建数据库

    create database Library

    创建表

    create table Users

    (

    UID int primary key,

    userName nvarchar(20) not null,

    userPwd nvarchar(20) not null

    )

    查询语句

    select * from StuInfo

    select Sex,Age from StuInfo

    select * from StuInfo where Sex='男' and (Age = 21 or Age=22)

    select * from StuInfo where Sex='男' and Age in(21,22)

    select * from StuInfo where Age>=10 and Age<=30

    select * from StuInfo where Age between 20 and 25

    select top 3 StuId,Sex from StuInfo where Sex='男' order by Age desc  //desc倒序

    select * from StuInfo where StuId like '%a%'

    select COUNT(*) as UserCount from StuInfo where Sex='男'  //count()统计

    select MIN(Age) as MinAge from StuInfo

    select MAX(Age) as MaxAge from StuInfo

    select Avg(Age) as AvgAge from StuInfo  //avg平均值

    select * from StuInfo where Age>

    (

    select Avg(Age) as AvgAge from StuInfo

    )

    select COUNT(*) as AgeCount,Age from StuInfo Group by Age  //分组

    having COUNT(*)=1 order by Age

    添加语句

    insert into StuInfo values('11','吧','女',20,'2005-7-30','','true','eqwe')

    insert into StuInfo(StuId,Age) values('qq',11)

    删除语句

    delete StuInfo where StuId='qq'

    更新语句

    update StuInfo set Sex='女' where ParenetId=1

    联合查询

    Left join      right join

    select * from
    (select ParenetId,ROW_NUMBER() over(order by ParenetId) as row from StuInfo) StuInfo
    where row between 1 and 20

    select MONTH(CredtedTime) as Credtedmoth from StuInfo

    select DATEADD(mm,1,getdate())

    select datediff(yy,getdate(),'2100')

    select StuId,ISNULL(FatherName,'')as FatherName from StuInfo

    select StuId,case
    when(StuId='aa') then 'UI哦'
    when(StuId='11') then 'U存在虚'
    end as A
    from StuInfo

    create proc procCategorySelect
    (
    @name varchar(200),
    @age int
    )
    as
    select * from StuInfo where StuName=@name and age=@age
    exec procCategorySelect 'xudads',11

    create trigger trigCategoryDelete
    ON StuInfo
    after delete /* 有三种INSERT,DELETE,UPDATE*/
    AS
    begin
    select * from deleted /*在删除后同时查出删除后的内容*/
    end

    delete StuInfo where StuId=4

    Backup DATABASE MyDB
    TO DISK = 'e:MyDB.bak'

  • 相关阅读:
    url向视图函数传递参数
    创建django项目
    进度百分比
    【转藏】Makefile学习
    IT人的自我导向型学习:学习的4个层次
    SZ第二次找工作--笔试汇总
    正则表达式 (re包)——python(快餐)
    Python-快速学习
    Vim的使用
    Vim Python
  • 原文地址:https://www.cnblogs.com/relstart/p/4893465.html
Copyright © 2011-2022 走看看