declare @Table_Name varchar(500)
declare @strSQL varchar(500)
set @Table_Name='UserInfo' --在此处设置要创建的表
if(not exists(SELECT  * FROM dbo.SysObjects WHERE ID = object_id(N''+@Table_Name+'') AND OBJECTPROPERTY(ID, 'IsTable') = 1))
begin
SET @strSQL='create  table '+@Table_Name+' ( id int IDENTITY(1,1) primary key )'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='id'))
begin
SET @strSQL='alter table '+@Table_Name+' add id int IDENTITY(1,1) primary key '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='CreateDate'))
begin
SET @strSQL=' alter table '+@Table_Name+' add CreateDate datetime'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='CreateUserID'))
begin
SET @strSQL=' alter table '+@Table_Name+' add CreateUserID int'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='CreateUser'))
begin
SET @strSQL=' alter table '+@Table_Name+' add CreateUser varchar(2000) '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='LastUpdateUserID'))
begin
SET @strSQL=' alter table '+@Table_Name+' add LastUpdateUserID int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='LastUpdateDate'))
begin
SET @strSQL=' alter table '+@Table_Name+' add LastUpdateDate datetime'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='LastUpdateUser'))
begin
SET @strSQL=' alter table '+@Table_Name+' add LastUpdateUser varchar(2000)'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='LastUpTimestamp'))
begin
SET @strSQL=' alter table '+@Table_Name+' add LastUpTimestamp timestamp'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='SortIndex'))
begin
SET @strSQL=' alter table '+@Table_Name+' add SortIndex int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='HotIndex'))
begin
SET @strSQL=' alter table '+@Table_Name+' add HotIndex int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='IsAudit'))
begin
SET @strSQL=' alter table '+@Table_Name+' add IsAudit int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='AuditDate'))
begin
SET @strSQL=' alter table '+@Table_Name+' add AuditDate datetime '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='IsHot'))
begin
SET @strSQL=' alter table '+@Table_Name+' add IsHot int'
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='IsDel'))
begin
SET @strSQL=' alter table '+@Table_Name+' add IsDel int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='DelDate'))
begin
SET @strSQL=' alter table '+@Table_Name+' add DelDate datetime '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='IsEnable'))
begin
SET @strSQL=' alter table '+@Table_Name+' add IsEnable int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='EnableDate'))
begin
SET @strSQL=' alter table '+@Table_Name+' add EnableDate datetime '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='Status'))
begin
SET @strSQL=' alter table '+@Table_Name+' add Status int '
exec (@strSQL)
end

if(not exists(select * from syscolumns  where id=object_id(''+@Table_Name+'') and name='Pid'))
begin
SET @strSQL=' alter table '+@Table_Name+' add Pid int'
exec (@strSQL)
end
go

创建数据库表默认字段封装SQL的更多相关文章

  1. django使用model创建数据库表使用的字段

    Django通过model层不可以创建数据库,但可以创建数据库表,以下是创建表的字段以及表字段的参数.一.字段1.models.AutoField 自增列= int(11) 如果没有的话,默认会生成一 ...

  2. 一、数据库表中字段的增删改查,二、路由基础.三、有名无名分组.四、多app共存的路由分配.五、多app共存时模板冲突问题.六、创建app流程.七、路由分发.八、路由别名,九、名称空间.十、反向解析.十一、2.x新特性.十二、自定义转换器

    一.数据库表中字段的增删改查 ''' 直接在modules中对字段进行增删改查 然后在tools下点击Run manage.py Task执行makemigrations和migrate 注意在执行字 ...

  3. SQLAlchemy通过models创建数据库表

    原地址:http://blog.csdn.net/jmilk/article/details/53184903 定义数据模型 models SQLAlchemy 允许我们根据数据库的表结构来创建数据模 ...

  4. DDL创建数据库,表以及约束(极客时间学习笔记)

    DDL DDL是DBMS的核心组件,是SQL的重要组成部分. DDL的正确性和稳定性是整个SQL发型的重要基础. DDL的基础语法及设计工具 DDL的英文是Data Definition Langua ...

  5. hibernate动态创建数据库表名几种方式

    数据库中数据量很大, 但又不可以删除时同时又要优化程序检索数据时间. 答:方式有很多比如 创建数据库表分区,创建索引, 存储过程等; 我这里采用动态创建数据库表的方式. 完全可以在不创建表分区情况下实 ...

  6. 使用PowerDesigner创建数据库表图文并茂版

    使用PowerDesigner创建数据库表图文并茂版 使用PowerDesigner 建数据库表. 一直很忙,没有时间写东西.这次搞点会声会色的,嘿嘿 此技能为项目经理必备技能. 本次主角: 1.在w ...

  7. Java 通过JDBC查询数据库表结构(字段名称,类型,长度等)

    Java 通过JDBC查询数据库表结构(字段名称,类型,长度等) 发布者:唛唛家的豆子   时间:2012-11-20 17:54:02   Java 通过JDBC查询数据库表结构(字段名称,类型,长 ...

  8. 基于CentOS的MySQL学习补充三--使用Shell批量创建数据库表

    本文出处:http://blog.csdn.net/u012377333/article/details/47006087 接上篇介绍<基于CentOS的Mysql学习补充二--使用Shell创 ...

  9. Python 创建数据库表

    创建数据库表 如果数据库连接存在我们可以使用execute()方法来为数据库创建表,如下所示创建表EMPLOYEE: #!/usr/bin/python # -*- coding: UTF-8 -*- ...

随机推荐

  1. canvas-海底气泡(面向对象编程)

    需求:自动生成若干气泡,从海底往上浮: 1.基本的HTML结构: <!DOCTYPE html> <html> <head lang="en"> ...

  2. Springboot security cas源码陶冶-CasAuthenticationFilter

    Springboot security cas整合方案中不可或缺的校验Filter类或者称为认证Filter类,其内部包含校验器.权限获取等,特开辟新地啃啃 继承结构 - AbstractAuthen ...

  3. JdbcTemplate的使用

    NamedParameterJdbcTemplate中包含了一个JdbcTemplate,NamedParameterJdbcTemplate中的很多方法实际上还是交由JdbcTemplate去完成. ...

  4. 快速傅里叶变换 & 快速数论变换

    快速傅里叶变换 & 快速数论变换 [update 3.29.2017] 前言 2月10日初学,记得那时好像是正月十五放假那一天 当时写了手写版的笔记 过去近50天差不多忘光了,于是复习一下,具 ...

  5. BZOJ 3744: Gty的妹子序列 [分块]

    传送门 题意:询问区间内逆序对数 感觉这种题都成套路题了 两个预处理$f[i][j]$块i到j的逆序对数,$s[i][j]$前i块$\le j$的有多少个 f我直接处理成到元素j,方便一点 用个树状数 ...

  6. 51Nod 1225 余数之和 [整除分块]

    1225 余数之和 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 F(n) = (n % 1) + (n % 2) + (n % 3) + ... ...

  7. python---协程 学习笔记

    协程 协程又称为微线程,协程是一种用户态的轻量级线程 协程拥有自己的寄存器和栈.协程调度切换的时候,将寄存器上下文和栈都保存到其他地方,在切换回来的时候,恢复到先前保存的寄存器上下文和栈,因此:协程能 ...

  8. JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能

    1 学习计划 1.datagrid使用方法(重要) n 将静态HTML渲染为datagrid样式 n 发送ajax请求获取json数据创建datagrid n 使用easyUI提供的API创建data ...

  9. shell实现centos7双网卡修改网卡名eth0,eth1,并设置网络

    #!/bin/bash interface1=`ls /sys/class/net|grep en|awk 'NR==1{print}'` interface2=`ls /sys/class/net| ...

  10. 关于目前自己iOS项目使用的第三方开源库

    1.AFNetworking 目前比较推荐的iOS网络请求组件,默认网络请求是异步,通过block回调的方式对返回数据进行处理. 2.FMDB 对sqlite数据库操作进行了封装,demo也比较简单. ...