随笔分类 - SQL
摘要:1. 限制返回的行 select top 10 * from tablename2. 返回随机n行 select top n * from tablename order by newid()
阅读全文
摘要:select name, sal,case when sal >= 4000 then 'Good' when sal <= 2000 then 'Bad' else 'Ok'end as Statusfrom tablename
阅读全文
摘要:存储过程的定义:create procedure procedurename@param1 nvarchar(30)asselect * from tablename where name = @param1go存储过程调用exec procedurename N'test1'exec procedurename @param1=N'test1';GO
阅读全文
摘要:SQL查询的一般形式,以及被逻辑处理的顺序(8) select (9) distinct (11) (1) from (3) join (2) ON (4) where (5) group by (6) with {CUBE | ROLLUP}(7) Having (10) Order by 每个步骤都会产生一个虚拟表,该虚拟表被用作下一个步骤的输入。三值逻辑 TRUE, FALSE, UNKNOWN, SQL中的UNKOWN逻辑值通常出现在包含NULL值的逻辑表达式中(NULL>42)。NULL通常表示丢失或不相关的值。
阅读全文
摘要:批量插入测试数据use Testdeclare @count INTset @count = 0while(@count < 10)begin waitfor delay '000:00:10'insert into Northwind(CategoryName,[Description])values('Beverages', 'test')set @count=@count+1end数据库分页-用到ROW_NUMBE()select * from (select *, ROW_NUMBER() over (order by Id) as
阅读全文
摘要:删除数据库 drop database database-name创建新表格create table tablename (col1 type1 [not null] [primary key], col2 type2 [not null], ...)select top 0 * into tablenew from tableold or select * into b from a where 11- copy the schema without dataselect * into tablenew from tableold or insert into b(a,b,c) select
阅读全文
摘要:症状:安装了Azure SDK后,新建一个Web Role,F5启动程序,弹出一个Storage Emulator Initialization对话框显示以下错误信息:==============================================Attempting to use server specified.User specified an instance through /server or /sqlInstance options.Probing Failed. Retrying probe for localDBProbing SQL Instance: '
阅读全文
摘要:症状:当安装了VS2010以后,会自带安装上SQL Express,试图启动MSSQL$SQLEXPRESS服务时,遇到"the log scan number passed to log scan in database 'master' is not valid"错误。原因:C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Template Data目录下的master.mdf和master.ldf文件被破坏了。解决方案:在网上搜索了一下解决方案:到C:\Program File
阅读全文

浙公网安备 33010602011771号