varchar

Microsoft SQL Server 2005 数据类型

断了今生、忘了曾经 提交于 2020-02-25 14:18:53
序号 类别 SQL C# 备注 1 整数 bit Boolean True转换为1,False转换为0 2 tinyint Byte C#数据类型都位于System命名空间 3 smallint Int16 4 int Int32 5 bigint Int64 6 smallmoney decimal 7 money decimal 8 numeric decimal 9 decimal decimal 10 浮点数 float double 11 real single 12 日期和时间 smalldatetime datetime 13 datetime datetime 14 timestamp datetime 15 字符串 char string 16 text string 17 varchar string 18 nchar string 19 ntext string 20 nvarchar string 21 二进制数据 binary Byte[] 22 varbinary Byte[] 23 image Byte[] 24 其他 uniqueidentifier guid 25 variant object SQL Server 2005的数据类型与SQL 2000有一些不同,在创建表时,列的数据类型需要注意几点 用varchar(max)代替text

SQL Server中易混淆的数据类型

坚强是说给别人听的谎言 提交于 2020-02-25 14:17:53
(1)char、varchar、text和nchar、nvarchar、ntext char和varchar的长度都在1到8000之间,它们的区别在于char是定长字符数据,而varchar是变长字符数据。所谓定长就是长度固定的,当输入的数据长度没有达到指定的长度时将自动以英文空格在其后面填充,使长度达到相应的长度;而变长字符数据则不会以空格填充。text存储可变长度的非Unicode数据,最大长度为2^31-1(2,147,483,647)个字符。 后面三种数据类型和前面的相比,从名称上看只是多了个字母"n",它表示存储的是Unicode数据类型的字符。写过程序的朋友对Unicode应该很了解。字符中,英文字符只需要一个字节存储就足够了,但汉字众多,需要两个字节存储,英文与汉字同时存在时容易造成混乱,Unicode字符集就是为了解决字符集这种不兼容的问题而产生的,它所有的字符都用两个字节表示,即英文字符也是用两个字节表示。nchar、nvarchar的长度是在1到4000之间。和char、varchar比较:nchar、nvarchar则最多存储4000个字符,不论是英文还是汉字;而char、varchar最多能存储8000个英文,4000个汉字。可以看出使用nchar、nvarchar数据类型时不用担心输入的字符是英文还是汉字,较为方便,但在存储英文时数量上有些损失。 (2

Sql Server参数化查询之where in和like实现详解

荒凉一梦 提交于 2020-02-24 08:40:39
转 “ Sql Server参数化查询之where in和like实现详解 文章导读 拼SQL实现where in查询 使用CHARINDEX或like实现where in 参数化 使用exec动态执行SQl实现where in 参数化 为每一个参数生成一个参数实现where in 参数化 使用临时表实现where in 参数化 like参数化查询 xml和DataTable传参 身为一名小小的程序猿,在日常开发中不可以避免的要和where in和like打交道,在大多数情况下我们传的参数不多简单做下单引号、敏感字符转义之后就直接拼进了SQL,执行查询,搞定。若有一天你不可避免的需要提高SQL的查询性能,需要一次性where in 几百、上千、甚至上万条数据时,参数化查询将是必然进行的选择。然而如何实现where in和like的参数化查询,是个让不少人头疼的问题。 where in 的参数化查询实现 首先说一下我们常用的办法,直接拼SQL实现,一般情况下都能满足需要 string userIds = "1,2,3,4"; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand comm = new SqlCommand(); comm.Connection

SQL的一些经典算法

纵然是瞬间 提交于 2020-02-24 07:20:59
1 SQL分页查询,每页10个数据,取第三页 A) 如果有id列 select top(10) * from Spider_Hotel where Spider_Hotel.HotelId not in ( select top (10*2) Spider_Hotel.HotelId from Spider_Hotel) B) 如果没有id列 select top (10) * from (select ROW_NUMBER() over (order by Name) as Row,* from Spider_Hotel) a where Row>10*2 C) 如果有id列 select top (10) * from Spider_Hotel where HotelId >(select max(HotelId) from (select top (10*2) HotelId from Spider_Hotel order by HotelId) as a ) 2,数据库删除重复记录。 a, 如果有id列 a,b,c 重复 Delete from table where id not in (select max (id) from table group a,b,c) b, 如果没有id列a,b,c 重复 .用row_number() over 函数,制造个Id列 With

存储过程分页

≡放荡痞女 提交于 2020-02-22 15:17:57
//数据库存储过程 --存储过程 create PROCEDURE commonPagination @columns varchar(500), --要显示的列名,用逗号隔开 @tableName varchar(100), --要查询的表名 @orderColumnName varchar(100), --排序的列名 @order varchar(50), --排序的方式,升序为asc,降序为 desc @where varchar(100), --where 条件,如果不带查询条件,请用 1=1 @pageIndex int, --当前页索引 @pageSize int, --页大小(每页显示的记录条数) @pageCount int out --总页数,输出参数 as begin declare @sqlRecordCount nvarchar(1000) --得到总记录条数的语句 declare @sqlSelect nvarchar(1000) --查询语句 set @sqlRecordCount=N'select @recordCount=count(*) from ' +@tableName + ' where '+ @where declare @recordCount int --保存总记录条数的变量 exec sp_executesql

几种常见SQL分页存储过程方式效率比较

时光毁灭记忆、已成空白 提交于 2020-02-20 01:07:17
1.创建测试环境,(插入100万条数据大概耗时5分钟)。 create database DBTestuse DBTest--创建测试表create table pagetest(id int identity(1,1) not null,col01 int null,col02 nvarchar(50) null,col03 datetime null)--1万记录集declare @i intset @i=0while(@i<10000)begin insert into pagetest select cast(floor(rand()*10000) as int),left(newid(),10),getdate() set @i=@i+1end 复制代码 2.几种典型的分页sql,下面例子是每页50条,198*50=9900,取第199页数据。 --写法1,not in/topselect top 50 * from pagetest where id not in (select top 9900 id from pagetest order by id)order by id--写法2,not existsselect top 50 * from pagetest where not exists (select 1 from (select top 9900 id

常见SQL分页方式效率比较

房东的猫 提交于 2020-02-20 01:03:45
结一下。 1.创建测试环境,(插入100万条数据大概耗时5分钟)。 create database DBTestuse DBTest--创建测试表create table pagetest(id int identity(1,1) not null,col01 int null,col02 nvarchar(50) null,col03 datetime null)--1万记录集declare @i intset @i=0while(@i<10000)begin insert into pagetest select cast(floor(rand()*10000) as int),left(newid(),10),getdate() set @i=@i+1end 2.几种典型的分页sql,下面例子是每页50条,198*50=9900,取第199页数据。 --写法1,not in/topselect top 50 * from pagetest where id not in (select top 9900 id from pagetest order by id)order by id--写法2,not existsselect top 50 * from pagetest where not exists (select 1 from (select top 9900 id

几种常见SQL分页方式效率比较

别等时光非礼了梦想. 提交于 2020-02-20 00:59:31
原文地址: 几种常见SQL分页方式效率比较 分页很重要,面试会遇到。不妨再回顾总结一下。 1.创建测试环境,(插入100万条数据大概耗时5分钟)。 create database DBTestuse DBTest--创建测试表create table pagetest(id int identity(1,1) not null,col01 int null,col02 nvarchar(50) null,col03 datetime null)--1万记录集declare @i intset @i=0while(@i<10000)begin insert into pagetest select cast(floor(rand()*10000) as int),left(newid(),10),getdate() set @i=@i+1end 2.几种典型的分页sql,下面例子是每页50条,198*50=9900,取第199页数据。 --写法1,not in/topselect top 50 * from pagetest where id not in (select top 9900 id from pagetest order by id)order by id--写法2,not existsselect top 50 * from pagetest where not

几种常见SQL分页方式效率比较

风格不统一 提交于 2020-02-20 00:56:15
分页很重要,面试会遇到。不妨再回顾总结一下。 1.创建测试环境,(插入100万条数据大概耗时5分钟)。 create database DBTestuse DBTest--创建测试表create table pagetest(id int identity(1,1) not null,col01 int null,col02 nvarchar(50) null,col03 datetime null)--1万记录集declare @i intset @i=0while(@i<10000)begin insert into pagetest select cast(floor(rand()*10000) as int),left(newid(),10),getdate() set @i=@i+1end 2.几种典型的分页sql,下面例子是每页50条,198*50=9900,取第199页数据。 --写法1,not in/topselect top 50 * from pagetest where id not in (select top 9900 id from pagetest order by id)order by id--写法2,not existsselect top 50 * from pagetest where not exists (select 1 from

SQLServer 简单数据拆分

夙愿已清 提交于 2020-02-17 07:24:46
-1. 旧的解决方法(sql server 2000) create table tb(id int,value varchar(30)) insert into tb values(1,'aa,bb') insert into tb values(2,'aaa,bbb,ccc') go --方法1.使用临时表完成 SELECT TOP 8000 id = IDENTITY(int, 1, 1) INTO # FROM syscolumns a, syscolumns b SELECT A.id, value = SUBSTRING(A.[value], B.id, CHARINDEX(',', A.[value] + ',', B.id) - B.id) FROM tb A, # B WHERE SUBSTRING(',' + A.[value], B.id, 1) = ',' DROP TABLE # --方法2.如果数据量小,可不使用临时表 select a.id , value = substring(a.value , b.number , charindex(',' , a.value + ',' , b.number) - b.number) from tb a join master..spt_values b on b.type='p' and b.number