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 ...
随机推荐
- a better git log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d ...
- 移动端的0.5px
最近写移动端页面写的比较多,边边基本上都是用的1px,视觉上也确实有点小粗,这不闲下来啦,具体的研究了下0.5px是怎么实现的,切记,这个效果只有在手机上才能看到效果的 利用了css3的缩放效果 &l ...
- 前端手机验证码cookie存储
注册的时候经常会有手机验证码的输入这个环节,在第一次点击发送了验证码只后,比如倒计时只走了10秒钟,然后刷新的话,倒计时要还是存在的,这个时候就要有一个cookie的存在了. html的代码 < ...
- ajax发送请求是图标转圈圈实现
css部分 .load-img{ //控制图标大小width:40px;height:40px;margin:100px;border-radius:50%;-webkit-animation:cir ...
- Vue中的v-model与my97日期选择插件冲突
Vue中的v-model指令只是一个语法糖,其具体实现是:监听input框的input事件,然后将用户输入的值赋值给input框的value属性 <input type="text&q ...
- 补充01 Django 类视图
视图 函数视图[Function Base View] 以函数的方式定义的视图称为函数视图,函数视图便于理解.但是遇到一个视图对应的路径提供了多种不同HTTP请求方式的支持时,便需要在一个函数中编写不 ...
- Javase 简单练习
public class Test10 { public static void main(String[] args) { System.out.println("------------ ...
- SQL Server UPDATE语句的用法详解
SQL Server UPDATE语句用于更新数据,下面就为您详细介绍SQL Server UPDATE语句语法方面的知识,希望可以让您对SQL Server UPDATE语句有更多的了解. 现实应用 ...
- Vue学习之路第十三篇:v-for指令
v-for指令,看名字想必大家也能猜到其作用,没错,就是用来迭代.遍历的. 1.简单数组的遍历 <body> <divi id="app"> <spa ...
- [BZOJ4916]神犇(Monster_Qi)和蒟蒻(SWHsz)
很久很久以前,有一只神犇叫Monster_Qi; 很久很久之后,有一只蒟蒻叫SWHsz; 1<=N<=1E9,A.B模1E9+7; 求这个. 求μ的话直接输出1就行了因为除了1的平方外都有 ...