创建数据库表默认字段封装SQL
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的更多相关文章
- django使用model创建数据库表使用的字段
Django通过model层不可以创建数据库,但可以创建数据库表,以下是创建表的字段以及表字段的参数.一.字段1.models.AutoField 自增列= int(11) 如果没有的话,默认会生成一 ...
- 一、数据库表中字段的增删改查,二、路由基础.三、有名无名分组.四、多app共存的路由分配.五、多app共存时模板冲突问题.六、创建app流程.七、路由分发.八、路由别名,九、名称空间.十、反向解析.十一、2.x新特性.十二、自定义转换器
一.数据库表中字段的增删改查 ''' 直接在modules中对字段进行增删改查 然后在tools下点击Run manage.py Task执行makemigrations和migrate 注意在执行字 ...
- SQLAlchemy通过models创建数据库表
原地址:http://blog.csdn.net/jmilk/article/details/53184903 定义数据模型 models SQLAlchemy 允许我们根据数据库的表结构来创建数据模 ...
- DDL创建数据库,表以及约束(极客时间学习笔记)
DDL DDL是DBMS的核心组件,是SQL的重要组成部分. DDL的正确性和稳定性是整个SQL发型的重要基础. DDL的基础语法及设计工具 DDL的英文是Data Definition Langua ...
- hibernate动态创建数据库表名几种方式
数据库中数据量很大, 但又不可以删除时同时又要优化程序检索数据时间. 答:方式有很多比如 创建数据库表分区,创建索引, 存储过程等; 我这里采用动态创建数据库表的方式. 完全可以在不创建表分区情况下实 ...
- 使用PowerDesigner创建数据库表图文并茂版
使用PowerDesigner创建数据库表图文并茂版 使用PowerDesigner 建数据库表. 一直很忙,没有时间写东西.这次搞点会声会色的,嘿嘿 此技能为项目经理必备技能. 本次主角: 1.在w ...
- Java 通过JDBC查询数据库表结构(字段名称,类型,长度等)
Java 通过JDBC查询数据库表结构(字段名称,类型,长度等) 发布者:唛唛家的豆子 时间:2012-11-20 17:54:02 Java 通过JDBC查询数据库表结构(字段名称,类型,长 ...
- 基于CentOS的MySQL学习补充三--使用Shell批量创建数据库表
本文出处:http://blog.csdn.net/u012377333/article/details/47006087 接上篇介绍<基于CentOS的Mysql学习补充二--使用Shell创 ...
- Python 创建数据库表
创建数据库表 如果数据库连接存在我们可以使用execute()方法来为数据库创建表,如下所示创建表EMPLOYEE: #!/usr/bin/python # -*- coding: UTF-8 -*- ...
随机推荐
- 在SecureCRT中无需输入密码登录Linux主机
服务器端操作系统:CentOs 5.8客户端:SecureCRT5.1.3第一步:密钥对的生成.在SecureCRT中建立一个新的连接.protocol选ssh2hostname输入要连接的主机IP. ...
- 看图说话,P2P 分享率 90% 以上的 P2P-CDN 服务,来了!
事情是这样的:今年年初的时候,公司准备筹划一个直播项目,在原有的 APP 中嵌入直播模块,其中的一个问题就是直播加速服务的选取. 老板让我负责直播加速的产品选型,那天老板把我叫到办公室,语重心长地说: ...
- WebService 的工作原理
Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的 ...
- Java多线程基础(二)
信号量Semaphore,类似于锁的功能,用于多线程中对一组资源的控制. acquire方法用于尝试获取一个资源,未获取前将一直等待.release用于释放一个资源,release的前提是已经获得了一 ...
- 最大流模版 dinic
朴素dinic+多路增广 #include <iostream> #include <cstdio> #include <cstring> #include < ...
- Linux 常用命令 (common commands for linux)
Linux 常用命令 (Common Commands For Linux) 1.声明,此文章仅写基于 Bash shell 常用的命令,如果遇上命令在使用过程中提示没有,可能随着更新,命令也被替换掉 ...
- 从一个实例学习----FLASK-WTF
本案例通过实现一个注册页面的编写,来带你了解FLASK-WTF的运用. 主要功能为表单基础的功能--手机号码必须为11位数,且通过数据库查找不能有已经注册的了,密码要求输入两遍且必须一样,且所有内容不 ...
- [Python Study Notes]电池信息
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- Windows Server 2016-抢占FSMO角色
很多情况下,当生产域控制器发生问题无法修复的情况下,我们只能通过抢占FSMO角色以保证用户验证等正常或及时恢复.一般在同一个域环境中,我们往往都会有主备或主辅域控规划,平时工作的时候,两台域控可以实现 ...
- Html5本地存储和本地数据库
一个网站如何能在客户的浏览器存储更多的数据呢? 在Html4的时代在浏览器端存储点网站个性化的数据,尤其是用户浏览器的痕迹,用户的相关数据等一般只能存储在Cookie中,但是大多是浏览器对于Cooki ...