zoukankan      html  css  js  c++  java
  • sqlserver 常用的语句

    1.更新一个字段的类型

    alter table VendorForm
    alter column applicationCode char(30)

    2.添加/删除一个字段

    if Exists( select * from syscolumns where id = OBJECT_ID('Chop_ApplicationInfo') and name = 'junctionChop')
    alter table Chop_ApplicationInfo
    add junctionChop char(8)

    删除

    alter table  TableName

    drop column deleted

    3.更新表中一个字段的值

      update Student

      set age =29  where Id = 2

    4.更新表列名字的值

    sp_rename 'DAT_Form_4_1_1_D1.Name','name','column'

    5.更新表名字的值

    sp_rename 'DAT_Family','DAT_FamilyOld'

    6.在表中插入一行数据

    insert into Student ( name, age) 

    values 

    ('Tom', 28),

    ('LiLy', 25)

    7.创建表

    create table TableName ( 

      [Id] [int] IDENTITY(1,1) NOT NULL,
      [category] [nvarchar](128) not NULL

    )

    8.创建视图

    create view ViewName 

    as 

    select

      a.Id

      b.address

    from student as a

    left join school as b on a.schoolid = b.id;

    9.创建自定义函数

      标量值函数:

      create FUNCTION fn_week (@id int) 

      returns int 

      AS

      begin

        declare @d int

        set @d = Year(NOW()) + @id;

        return @d;

      end

      

      表值函数:

      create FUNCTION  Fun_Proc_WorkItem_AgencyApplication ( @ id  int)

      returns  table

      as

      return (

        select * from Student where id = @id

      )

    10.创建存储过程

      create PROCEDURE  PRO_Update_Student  @id

      AS

      BEGIN

        update Student set deleted = 1

        where id = @id

      END

  • 相关阅读:
    MySQL server version for the right syntax to use near ‘USING BTREE
    随笔
    [python]自问自答:python -m参数?
    [linux]查看linux下端口占用
    [linux]scp指令
    [编程题目]泥塑课
    How can I learn to program?
    [python]在场景中理解装饰器
    [前端]分享一个Bootstrap可视化布局的网站
    [python]python元类
  • 原文地址:https://www.cnblogs.com/kingsmart/p/12884214.html
Copyright © 2011-2022 走看看