• sql server 常用语句


    --新增字段
    
    use [MEASDatabase]
    go
    if not exists(select * from syscolumns where id=object_id('DictCheckItems') and name='OfDepartName') begin
    ALTER TABLE DictCheckItems ADD OfDepartName VARCHAR(50) default '';
    end
    go
    
    --修改字段长度
    
    alter table DictCheckItems alter column OfDepartName varchar(60)
    
     --新增表结构
    
    IF NOT EXISTS ( SELECT * FROM sysobjects WHERE id = object_id('TableInfo')
    AND OBJECTPROPERTY(id, 'IsUserTable') = 1)
    CREATE TABLE [dbo].TableInfo(
    [ID] [varchar](50) NOT NULL,
    [PARAMTYPE] [varchar](50) NOT NULL,
    [PARAMNAME] [varchar](100) NOT NULL,
    PARAMITEMS [varchar](500) not NULL
    CONSTRAINT [PK_DICT_PARAM] PRIMARY KEY CLUSTERED
    ([ID] ASC
    )ON [PRIMARY]
    )
    
    GO
    
    --删除字段
    
    alter table 表名 drop column 字段名;
    
    --修改字段名称
    
    exec sp_rename 'UserMEAS.PermissionID' , 'RoleCode', 'column'
    
    eg:
    
    if exists(select * from syscolumns where id=object_id('UserMEAS') and name='PermissionID') begin
    exec sp_rename 'UserMEAS.PermissionID' , 'RoleCode', 'column'
    end
    go
    
    if exists(select * from syscolumns where id=object_id('UserMEAS') and name='RoleId') begin
    alter table UserMEAS drop column [RoleId];
    end
    go
    
    --判断是否存在某条数据
    
    if not exists (select * from [DictPublic] where Type='默认密码')
    insert into DictPublic
    (Id, Type, TypeCode, TypeName, TypeLevel, IsEnable, Remark, PTypeCode)
    values(NEWID(),'默认密码','PassWord','666666','1','1','用户默认密码','')
    go
    
    
    --新增视图
    IF EXISTS(SELECT * FROM sysobjects WHERE id = object_id(N'[VIEW_USERINFO]') AND OBJECTPROPERTY(id, N'IsView') = 1)
       DROP View [VIEW_USERINFO]
    GO
    CREATE VIEW [dbo].[VIEW_USERINFO]
    AS 
    SELECT U.ID, LoginName, TrueName, PassWord, OrganizationCode, 
    Organization, DepartMent, SystemClass, UserType, StuffID, 
    UserParam, U.RoleCode
    RoleName, RoleRemark, PermissionCodes
    FROM [dbo].[UserMEAS] U,[dbo].[UserRole]
    WHERE U.RoleCode=UserRole.RoleCode  
    GO
    
    --left join
    ALTER VIEW [dbo].[VIEW_USERINFO]
    AS 
    SELECT U.ID, LoginName, TrueName, PassWord, OrganizationCode, 
    Organization, DepartMent, SystemClass, UserType, StuffID, 
    UserParam, U.RoleCode,
    RoleName, RoleRemark, PermissionCodes
    FROM [dbo].[UserMEAS] U
    --,[dbo].[UserRole]
    --WHERE U.RoleCode=UserRole.RoleCode  
    LEFT JOIN [dbo].[UserRole] 
    ON U.RoleCode=UserRole.RoleCode  
    
    GO
    

      

      

     

    博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
  • 相关阅读:
    MYsql 主从复制
    linux下修改apache,nginx服务端口号
    nginx的安装
    oracle启动流程
    openfire源码编译后部署到linux
    openfire重新配置数据库oracle、mysql
    spark安装和登陆配置
    Linux下安装Openfire 4.2.1
    mac toad下建表问题
    linux 下使用exp/imp 或者expdp/impdp导出导入oracle数据表数据
  • 原文地址:https://www.cnblogs.com/YYkun/p/15716515.html
Copyright © 2020-2023  润新知