随笔分类 - SQL
摘要:(select dd.*,t.RANK from crm_CustomerAnalyzeDetails dd inner join containstable(crm_CustomerAnalyzeDetails,KeyWords,'IsAbout(双子 weight(.5),string wei...
阅读全文
摘要:create database 数据库/*数据库的服务、数据库文件、*/--修改表添加列create table biao(name varchar(50))alter table biao add sex varchar(20) --往表里增加一列alter table biao drop col...
阅读全文
摘要:--范式理论(数据库设计三范式)--1.列里面数据要单一--2.一个表必须要有一个主键--3.外键表中只出现主键表中的主键列就好了,其他列就不要出现了/*当一个表中,出现了3列及以上的数据经常重复出现多次的情况的时候,就需要把这些列拿出来单独建立一个表,设一个主键,然后在原来表中只出现主键就可以了*...
阅读全文
摘要:---事务:保障整个流程的完整执行,全部没有问题,统一提交,一旦有问题,回到原点。begin tran --事务的开始--开始写流程语句--语句写完之后if @@ERROR>0beginrollback tran--回滚事务endelsecommit tran --提交事务--级联删除套入事务中al...
阅读全文
摘要:alter trigger studentchufa_deleteon studentchufainstead of deleteas declare @count int select @count=count(*)from deleted declare @i int s...
阅读全文
摘要:--触发器:触发器就是一种特殊的存储过程--特殊的地方在于,触发器是通过对数据库表的操作,来引发--存储过程是通过人为exec来执行select*from studentcreate trigger student_insert --创建触发器on student --指定触发器所在的表for In...
阅读全文
摘要:--累加求和存储过程alter proc LeiJiaQiuHe1 @num int--输入参数asdeclare @sum intdeclare @i intset @sum=0set @i=1while @i<=@num begin set @sum=@sum+@i set @...
阅读全文
摘要:--约束:对列的值起一个约束性的作用,规定列的值的范围--主键、外键、非空、自增长标识列、唯一列(unique)、check约束--check 约束--在某个表里点击右键→设计→进去找到要约束的列点击右键→添加→写表达式(表达式必须以列名开头)
阅读全文
摘要:--数据库的备份、还原--备份--在对应数据库右键→任务→备份→直接点确定 .bak结尾--还原--在数据库右键→还原数据库→目标数据库(起别名),点击源设备→添加所备份的.bak文件--分离、附加--分离 分离出来可以拷贝走 .mdf文件--在对应数据库右键→任务→分离→删除连接→确定 ...
阅读全文
摘要:--创建万能分页alter proc wannengfenye11@nowye int,@numbers int,@tablename varchar(50),@zhujian varchar(50)as必须要用字符串连接起来,不然系统识别不出@tablenameexec ('select top(...
阅读全文
摘要:--视图:视图就是一个虚拟的表select *from view_1--显示所有学生的sno、sname、cno、degreeselect Student.Sno,sname,cno,degree from Student join Score on Student.Sno=Score.sno --...
阅读全文
摘要:create database Fruitcreate table fruit(Ids varchar(50),Name varchar(50),Price decimal(18,2),Source varchar(50),Stack int,Numbers int,Image varchar(50...
阅读全文
摘要:--定义变量 定义,赋值,显示 三个必须一块执行declare @bianliang int--定义变量 set @bianliang=12--变量赋值select @bianliang --显示--定义两个变量求和declare @bianliang1 int ,@bianliang2 intse...
阅读全文
摘要:--27、查询出“计算机系“教师所教课程的成绩表。select * from Score where Cno in(select Cno from Course where Tno in(select tno from Teacher where Depart='计算机系'))--28、查询“计算...
阅读全文
摘要:--17、 查询“95033”班学生的平均分。select avg(degree) from Score where Sno in (Select Sno from Student where Class=95033)--18、 假设使用如下命令建立了一个grade表:现查询所有同学的Sno、Cno...
阅读全文
摘要:create database 作业use 作业--创建学生表create table Student(Sno char(3) primary key not null,Sname char(8) not null,Ssex char(2) not null,Sbirthday datetime ...
阅读全文
摘要:create table yyy(code int ,name varchar(50),sex varchar(50),age int,hight decimal(18,1),weight decimal(18,1),idno bigint,address varchar(50))insert in...
阅读全文
摘要:create database k20150419 --创建一个名为k20150419的数据库go --连接符use k20150419 --使用k20150419这个数据库gocreate table practice --创建一个名为practice的表(tno int primary key ...
阅读全文
摘要:select*fromxinxibiaowherehigh>163andsex='男'updatexinxibiaosetname='约里克'wherename='刘凯'--betweenand在什么和什么之间select*fromxinxibiaowherehighbetween165and175...
阅读全文
摘要:二、第二课createtableteacher(tnointprimarykeyidentity(1,1),--将tno设为主键(primarykeyidentity(1,1))tnamevarchar(50))goinsertintoteachervalues('张三')insertintotea...
阅读全文

浙公网安备 33010602011771号