SQL纯手写创建数据库到表内内容
建表啥的只点点鼠标,太外行了,不如来看看我的纯手写,让表从无到有一系列;还有存储过程临时表,不间断的重排序;
一:建数据库
create Database Show
on
primary
(
name= Show_data ,
filename= 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Show.mdf' ,
size=10MB,
maxsize=UNLIMITED,
filegrowth=% )
log on
(
name=Show_log,
filename='C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Show_log .ldf' ,
size=10MB,
maxsize=UNLIMITED,
filegrowth=%
)
二:建表
三:建外键
四:添加表数据
五:删除数据库、表、外键、存储过程
drop database Show; --删除数据库 drop table T_user;
drop table T_proMain;
drop table T_proType;
drop table T_proImg; --删除表 alter table T_proMain drop constraint fk_typeID
alter table T_proMain drop constraint fk_UID
alter table T_proImg drop constraint fk_proID --删除外键约束 drop proc proc_getPic --删除存储过程
删除数据库、表、外键、存储过程
六:建存储过程
create proc proc_getproM (
@Index int,
@Size int
)
as
begin
declare @ta table
(
[proID] [int]
)
insert into @ta(proID) select proID from (SELECT ROW_NUMBER() over ( order by CTR desc) as id ,* from T_proMain )a where id between @Index and @Size
declare @a int , @b varchar()
declare @tc table
(
[proID] int,
[proExp] varchar(),
[UName] varchar(),
[UrlName] varchar(max)
) while exists(select [proID] from @ta)
begin
-- select * from @ta;
select top @a=[proID] from @ta;
declare @c int
select @c =proID from T_proMain where proID=@a ; --proID declare @e varchar()
select @e=proExp from T_proMain where proID=@a ; --proExp 第一张的 项目名 declare @d varchar(),@l int;
select @l=UID from T_proMain where proID=@a ;
select @d=UName from T_user where UID=@l; --UName 也就是作者名
declare @tb table
(
[imgURL] varchar()
) insert into @tb (imgURL) select imgURL from T_proImg where proID=@a;
-- select * from @tb
declare @g varchar(max);
set @g='';
while exists(select [imgURL] from @tb)
begin
select top @b=[imgURL] from @tb;
declare @f varchar() select @f=imgURL from T_proImg where imgURL=@b ; --imgURL 第一张的图片地址
set @g+=@f;
set @g+='#';
print @f;
declare @h varchar()
select @h=imgName from T_proImg where imgURL=@b ; --imgName 第一张的图片地址
print @h;
declare @o bit
select @o=ISDefault from T_proImg where imgURL=@b ;
set @g+=@h;
set @g+='#';
declare @n bit,@p varchar()
set @n=;
if @o=@n
begin
set @p=''
end
else
begin
set @p=''
end
set @g+=@p;
set @g+='*';
print @g;
delete from @tb where [imgURL] = @b;
end insert into @tc values(@c,@e,@d,@g);
delete from @tb;
delete from @ta where [proID]=@a;
end
select * from @tc;
end
建存储过程:动态取出另一张ID连续等于第几条到第几条,在这张表的数据
create proc proc_getPic (
@Index int,
@Size int
)
as
begin
declare @ta table
(
[ID] [int]
)
insert into @ta(ID) select ID from (SELECT ROW_NUMBER() over ( order by ID desc) as id from T_Pic )aa where ID between @Index and @Size
declare @a int , @b varchar()
declare @tc table
(
[ID] int,
[Pic] varchar(),
[PicName] varchar(),
[PicAuthor] varchar()
) while exists(select [ID] from @ta)
begin
-- select * from @ta;
select top @a=[ID] from @ta;
declare @c int
select @c =ID from T_Pic where ID=@a ; --proID declare @e varchar()
select @e=Pic from T_Pic where ID=@a ; --proExp 第一张的 项目名 declare @d varchar(),@l varchar();
select @l=PicName from T_Pic where ID=@a ;
select @d=PicAuthor from T_Pic where ID=@a; --UName 也就是作者名 insert into @tc values(@c,@e,@l,@d); delete from @ta where [ID]=@a;
end
select * from @tc;
end
exec proc_getPic ,
动态取出表的连续的第几条到第几条数据
希望能帮到有需要的人;
--一个快乐的码农!
SQL纯手写创建数据库到表内内容的更多相关文章
- 第16课-数据库开发及ado.net-数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍
第16课-数据库开发及ado.net 数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍 SQL语句入门(脚本.命令) SQL全名是结构化查询语言(Structur ...
- 创建数据库和表的SQL语句【转】
创建数据库和表的SQL语句 转至http://www.cnblogs.com/philanthr/archive/2011/08/09/2132398.html 创建数据库的SQL语句: 1 crea ...
- 纯手写Myatis框架
1.接口层-和数据库交互的方式 MyBatis和数据库的交互有两种方式: 使用传统的MyBatis提供的API: 使用Mapper接口: 2.使用Mapper接口 MyBatis 将配置文件中的每一个 ...
- springmvc 动态代理 JDK实现与模拟JDK纯手写实现。
首先明白 动态代理和静态代理的区别: 静态代理:①持有被代理类的引用 ② 代理类一开始就被加载到内存中了(非常重要) 动态代理:JDK中的动态代理中的代理类是动态生成的.并且生成的动态代理类为$Pr ...
- PHP创建数据库数据表
PHP创建数据库数据表 <?php $con = mysql_connect('localhost', 'root', 'root'); /************************在数据 ...
- ylb:创建数据库、表,对表的增查改删语句
ylbtech-SQL Server:SQL Server-创建数据库.表,对表的增查改删语句 SQL Server 创建数据库.表,对表的增查改删语句. 1,ylb:创建数据库.表,对表的增查改删语 ...
- Sql Server——运用代码创建数据库及约束
在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...
- Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表,以及同步和异步执行模式)
系列文章导航 Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表) Adobe AIR中使用Flex连接Sqlite数据库(2)(添加,删除,修改以及语句参数) Adobe ...
- centos环境下创建数据库和表的方法
centos环境下创建数据库和表的方法 //查询数据库的命令: mysql> SHOW DATABASES; +--------------------+ | Database ...
随机推荐
- 数据结构——单链表java简易实现
巩固数据结构 单链表java实现 单链表除了表尾 每个几点都有一个后继 结点有数据和后继指针组成 通过构建表头和表尾(尾部追加需要)两个特殊几点 实现单链表的一些操作,代码如下 package co ...
- Nginx配置Q&A
隐藏响应头 How can remove Nginx from http response header? - Stack Overflow more_set_headers 'Server: my- ...
- TF从文件中读取数据
从文件中读取数据 在TensorFlow中进行模型训练时,在官网给出的三种读取方式,中最好的文件读取方式就是将利用队列进行文件读取,而且步骤有两步: 把样本数据写入TFRecords二进制文件 从队列 ...
- BZOJ 1221 [HNOI2001] 软件开发 费用流_建模
题目描述: 某软件公司正在规划一项n天的软件开发计划,根据开发计划第i天需要ni个软件开发人员,为了提高软件开发人员的效率,公司给软件人员提供了很多的服务,其中一项服务就是要为每个开发人员每天提供 ...
- elasticsearch批量操作
1.批量查询的好处 就是一条一条的查询,比如说要查询100条数据,那么就要发送100次网络请求,这个开销还是很大的 如果进行批量查询的话,查询100条数据,就只要发送1次网络请求,网络请求的性能开销缩 ...
- lsync 负载实现代码双向同步
参考文件: https://www.zyku.net/centos/1713.html 检查错误命令: lsyncd -pidfile /tmp/lsyncd.pid /etc/lsyncd.con ...
- 原生js实现form表单序列化
当我们有form表单而且里面的表单元素较多时,咱们总不能一个个去获取表单元素内的值来进行拼接吧!这样会很让人蛋疼!为了方便与后台交互并且提高自己的开发效率,并且不让你蛋疼:我们一起用原生来写一个表单序 ...
- HDU2516 - 取石子游戏【斐波那契博弈】
基本描述 有一堆个数为n的石子,游戏双方轮流取石子,满足: 先手不能再第一次把所有石子取完: 之后每次可以取的石子数介于1到对手刚取的石子数的2倍之间,包括1和对手取的石子数的2倍. 取最后石子的人 ...
- 字符识别Python实现 图片验证码识别
字符型图片验证码识别完整过程及Python实现 1 摘要 验证码是目前互联网上非常常见也是非常重要的一个事物,充当着很多系统的 防火墙 功能,但是随时OCR技术的发展,验证码暴露出来的安全问题也越 ...
- Maya 2012 破解安装全图文教程
在学习U3D的过程中.我们要用到Maya这个工具,(当然你也能够用其它类似的), 我在安装破解 Maya 2012 的过程其中,走了一些弯路.通过搜索发现,网上关于Maya 破解的文章大多语焉不详,为 ...