zoukankan      html  css  js  c++  java
  • SQL的一些基本操作语法

    创建数据库:create DataBase   数据库的名字

    创建表:

    create table 表名
    (
    字段 类型 [约束]
    字段 类型 [约束]
    )

    创建约束:

    ->建约束
    alter table test add constraint PK_text_column primary key(_column) --主键约束
    alter table test add constraint DK_text_column default(_value) for _column --默认约束
    alter table test add constraint CK_test_column check(sex='男'or sex='女') --检查约束
    alter table test add constraint UQ_test_column unique(_column) --唯一约束
    alter table test1 add constraint FK_test1_test2_column foreign key (_column1) references


    insert into 表名(字段名) values ('1','2','3','4')
    select _column into _table_new from _table_old --要求表是存在的
    insert into _table_new select * from _table_old --要求表是不存在的


    delete from 表名 where 条件
    truncate table 表名;--所以有数据归零
    drop table _table
    drop database _database


    update 表名 set _column = _values,_column = _values where condition


    ->from 字句
    ->where字句
    ->group by 子句
    ->having 子句
    ->select top distinct
    ->order by

    表与表的连接
    ->交叉连接
    select * from _table1 cross join _table2;
    ->内连接
    select * from _table1 inner join _table2 on ID=ID
    ->外联接
    select * from _table1 left join _table2 on ID=ID
    ->自连接、多表连接
    表join表on。。。join表on。。。

    创建分页的存储过程

    create proc 存储过程的名字

    @pageIndex int=1, --页码(这里设置了默认值,也可以不用设置)
    @pageSize int =5 ---页容量
    as
    select * from
    (select ROW_NUMBER() over (order by stuid) as num,* from Student ) as temp
    where num between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize

  • 相关阅读:
    关于C++名字空间
    选择组合OR继承?
    编译器为C++ 空类自动生成的成员函数
    函数返回值为引用类型
    关于数据库存储过程分页DatagridView BindingNavigator 控件的详细实现
    ADO.NET 安全编码指南 来自MSDN
    ADO.NET中调用存储过程
    视图
    高效使用连接的模式
    GROUP BY, HAVING, COMPUTE, ORDER BY 语句
  • 原文地址:https://www.cnblogs.com/shinelhui/p/2953750.html
Copyright © 2011-2022 走看看