zoukankan      html  css  js  c++  java
  • SQL Server常用命令

    创建数据库:

       命令:create database 数据库名;

    删除数据库:

      命令:drop database 数据库名;

    新建表格:

      命令:create table 表名

                  (列名  数据类型,列名2.....)

      示例:create table student

                 (sname  char(20),sid  int)

    删除表格:

      命令:drop table 表名

      示例:drop table student

    修改表结构:

        (插入(新增)列)

        命令:alter table 表名

                     add 新列名  数据类型

        示例:alter table student

                     add  sage  int

        (删除列)

        命令:alter table 表名

                       drop column 列名

        示例:alter table student

                       drop column sid

        (修改列类型)

        命令:alter table 表名

                      alter  column 列名  数据类型

        示例:alter table student

                      alter  column  sid  float(浮点型)

      (新增约束)

         命令:alter table 表名

                      alter column 列名  新数据类型

         示例:alter table student

                       alter column PK_sid  primary  key(sid)(新增的约束类型是主键约束)

      (删除约束)

        命令:alter table 表名

                      drop  列名

        示例:alter table student

                      drop PK_sid

    查询表内容:

      命令:select  要查询的数据列名

                  from 表名

                    where  筛选条件(无法对分组后的数据进行筛选)

    (高级搜索)【group  by 列名(分组)

                             having  筛选条件(只能对分组后的数据进行筛选)

                                order by  排序方式(控制数据最后输出的排列方式有正序:asc、倒叙:desc)】

      示例:select  sid

                 from student

                   where  sid=2

                        【group by sid

                                  having  sid=1

                                       order by desc】

    在表中插入数据:(值与列必须一一对应)

     命令:insert  into  表名

                    (列名 ,列名)

                values

                    (值,值)

      示例:insert  into  表名

                    (sname,sid,sage)

                values

                   (‘张三’,12,15)

    修改表中数据值:

      命令:update from 表名

                   set 列名=新值

      示例:update from student

                  set sname='李四'

    查询模式:(批量插入多条数据)

      命令:insert into 表名(值的总数必须和列的总数相同)

                    select  值,值,值  union all

                    select  值,值,值

      示例:insert  into  表名

                   select  '张三',15,18

                   select  '李四',16,19

    视图:

      命令:create view 视图名

                  as

                 select 列

                 from 表名

      示例:create view students

                  as

                     select sname

                         from student

  • 相关阅读:
    MySql数据库时区异常,java.sql.SQLException: The server time zone value '?й???׼ʱ?' is unrecognized or represents more than one time zone.
    SpringBoot中自定义properties文件配置参数并带有输入提示
    Springboot2.x 集成jsp
    Spring Boot使用AOP实现REST接口简易灵活的安全认证
    Spring Boot使用过滤器和拦截器分别实现REST接口简易安全认证
    Spring Boot使用RestTemplate消费REST服务的几个问题记录
    Spring Boot开发MongoDB应用实践
    Spring Boot定时任务应用实践
    Spring Boot缓存应用实践
    Spring Boot消息队列应用实践
  • 原文地址:https://www.cnblogs.com/Xbingbing/p/11569661.html
Copyright © 2011-2022 走看看