Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快速为 SqlServer 数据库每个表新增字段 #25

Open
topcss opened this issue May 30, 2019 · 0 comments
Open

快速为 SqlServer 数据库每个表新增字段 #25

topcss opened this issue May 30, 2019 · 0 comments

Comments

@topcss
Copy link
Owner

topcss commented May 30, 2019

  1. 在 SqlServer 中查询所有的表名
SELECT NAME FROM SYSOBJECTS WHERE XTYPE = 'U'
  1. 在 chrome 的控制台执行模板辅助方法
// 增加一些模板处理的方法
Object.assign(String.prototype, {
    /**
     * 用正则替换对应的字符串,并且生成多个模板代码
     * 基于模板(列表,正则)
     */
    toMany(listStr, reg) {
        let list = [];
        listStr.split(',').map(item => list.push(this.replace(reg, item)));
        return list.join('');
    },

    /**
     * 按顺序替换字符串
     * 基于内容(列表,正则)
     */
    replaceList(listStr, reg) {
        let list = listStr.split(','), index = 0;
        return this.replace(reg, (e, i) => list[index++]);
    },

    /**
     * 通过自定义函数,来替换指定的值
     * 基于内容(正则,函数)
     */
    replaceByFn(reg, fn) {
        let index = 0;
        return this.replace(reg, (item) => fn(item, (index++)));
    }
});
  1. 修改表名,执行即可复制脚本
copy(
// 为表新增字段的模板
`ALTER TABLE [dbo].[APPVERSION] ADD [ISDELETED] nvarchar(36) COLLATE Chinese_PRC_CI_AS  NULL;
EXEC sp_addextendedproperty 'MS_Description', N'是否删除', 'SCHEMA', N'dbo', 'TABLE', N'APPVERSION', 'COLUMN', N'ISDELETED';

`
.toMany(
// 需要新增字段的表名
`DCMSXX
GCJBXX
HCYC
Report
CZFA
CZFDXX
CZFLXX
DLCTFMX
FDFLDJB
LYZTFMX
XMCZXX
ZTFYMX
YTSYCGB
ZKBZGRSY
ZKCSSY
ZKCSSYJL
ZKDLCTSY
ZKDLCTSYJL
ZKFCXX
ZKHCXX
ZKHCXX_HCYCFH
ZKHCXX_ZKFH
ZKHCXX_ZKYC
ZKQYXX
ZKXX
ZKYSCS
ZKYSCSJL
ZTYC
APPVERSION
DataSource`.replace(/\n/ig,',')
,/APPVERSION/ig));

4.回到数据库中粘贴运行脚本即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant