建表啥的只点点鼠标,太外行了,不如来看看我的纯手写,让表从无到有一系列;还有存储过程临时表,不间断的重排序;

一:建数据库

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纯手写创建数据库到表内内容的更多相关文章

  1. 第16课-数据库开发及ado.net-数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍

    第16课-数据库开发及ado.net 数据库SQl,创建数据库和表,增删改语句,约束,top和Distinct,聚合函数介绍 SQL语句入门(脚本.命令) SQL全名是结构化查询语言(Structur ...

  2. 创建数据库和表的SQL语句【转】

    创建数据库和表的SQL语句 转至http://www.cnblogs.com/philanthr/archive/2011/08/09/2132398.html 创建数据库的SQL语句: 1 crea ...

  3. 纯手写Myatis框架

    1.接口层-和数据库交互的方式 MyBatis和数据库的交互有两种方式: 使用传统的MyBatis提供的API: 使用Mapper接口: 2.使用Mapper接口 MyBatis 将配置文件中的每一个 ...

  4. springmvc 动态代理 JDK实现与模拟JDK纯手写实现。

    首先明白 动态代理和静态代理的区别: 静态代理:①持有被代理类的引用  ② 代理类一开始就被加载到内存中了(非常重要) 动态代理:JDK中的动态代理中的代理类是动态生成的.并且生成的动态代理类为$Pr ...

  5. PHP创建数据库数据表

    PHP创建数据库数据表 <?php $con = mysql_connect('localhost', 'root', 'root'); /************************在数据 ...

  6. ylb:创建数据库、表,对表的增查改删语句

    ylbtech-SQL Server:SQL Server-创建数据库.表,对表的增查改删语句 SQL Server 创建数据库.表,对表的增查改删语句. 1,ylb:创建数据库.表,对表的增查改删语 ...

  7. Sql Server——运用代码创建数据库及约束

    在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...

  8. Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表,以及同步和异步执行模式)

    系列文章导航 Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表) Adobe AIR中使用Flex连接Sqlite数据库(2)(添加,删除,修改以及语句参数) Adobe ...

  9. centos环境下创建数据库和表的方法

    centos环境下创建数据库和表的方法 //查询数据库的命令: mysql> SHOW DATABASES; +--------------------+ | Database         ...

随机推荐

  1. 使用PyQT编写界面程序

    使用PyQT比QT好在,可以随时监测函数正确性,省去编译时间 ! 这是个不小的节省. 1. PyQt: 打开对话框 msgbox = QtGui.QMessageBox(self)# 我的语句是 ms ...

  2. jquery插件生成简单二维码

    除了利用第三方网站生成二维码外,这是一个比较简单的办法吧. <script src="/Scripts/jquery.qrcode.min.js" type="te ...

  3. RabbitMQ学习之基于spring-rabbitmq的RPC远程调用

    http://blog.csdn.net/zhu_tianwei/article/details/40920985 spring-rabbitmq中实现远程接口调用,主要在com.rabbitmq.s ...

  4. 后代children() find()的区别

    $(document).ready(function(){ $("div").children(); });只拿到div下面的子标签元素 $(document).ready(fun ...

  5. JS 封装一个对数组去重的函数

    var zz = [1,2,3,5,5,7,8,6,6]; var se = []; d(se); function d(attr){ for(var i = 1;i<zz.length;i++ ...

  6. 理解Faster-RCNN 中的Anchor

    先上图看一下Faster R-CNN操作流程:  图片说明:Faster R-CNN=Fast R-CNN+RPN,其中Fast R-CNN结构不变:RPN负责生成proposals,配合最后一层的f ...

  7. js和css引入文件消除缓存

    ?version=<?php echo filemtime('引用路径'); ?>

  8. Linux-workqueue讲解

    =============  参考  ============= 代码:linux-3.10.65/kernel/workqueue.c =============================== ...

  9. spring实现定时任务的两种方式之spring @scheduled注解方式

    1.使用spring的 scheduled使用注解的方式 这种方法的好处是:使用方便,配置少,提高开发效率: 缺点是:如果使用服务器集群部署方式的时候,其自身无法解决定时任务重复执行的问题. 2.首先 ...

  10. 搞定PHP面试 - 深入了解引用

    1. 什么是引用 在 PHP 中引用是指用不同的名字访问同一个变量内容.PHP 中的变量名和变量内容是不一样的, 因此同样的内容可以有不同的名字.最接近的比喻是 Unix 的文件名和文件本身--变量名 ...