随笔分类 - Server
摘要:convert(varchar(10),字段名,转换格式)CONVERT(nvarchar(10),count_time,121) CONVERT为日期转换函数,一般就是在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,char,varchar) 相互转换的时候才用到的函数的3个参数,第1个参数为,转换后的大小,第2个为转换日期的字段或函数,第3个为转换的格式.具体如下: 0 | 0 or 100 | mon dd yyyy hh:miAM(或PM) 1 | 101 | mm/dd/yy 2 | 102 | yy-mm-dd 3 | 103
阅读全文
摘要:select * from dbo.Vehicle_Maintain_Details A inner join (select MaintainType as tempTypeName,count(ID) as num from dbo.Vehicle_Maintain_Details group by MaintainType) B on A.MaintainType=B.tempTypeName
阅读全文
摘要:今天遇到个问题. 首先插入一个DataTime格式的数据: string sql="insert into [table] (date_time) values('" + date_time.ToString() + "'"; 执行如上命令.插入没有报告错误.但是,我又用一条命令读取时: string sql="select * from [table]; ..... IDataReader dr=cmd.ExecuteReader(); ... object obj=dr["data_time"];//在这
阅读全文
摘要:select top(10) * from T1 where Id >= (select MAX(Id) from (select top(20) * from T1 order by Id) as t)
阅读全文
摘要:SqlServer中更新时间主要使用DATEADD()这个函数具体使用方法如下:DATEADD(datepart,number,date)date 参数是合法的日期表达式。number 是您希望添加的间隔数;对于未来的时间,此数是正数,对于过去的时间,此数是负数。datepart指定更新的是年、月、日或者其他的时、分、秒等,对应的参数如下:年:YYYY YEAR月:MM MONTH日:D DD DAY时:HH HOUR分:MINUTE MI秒:S SECOND SS具体的请参考:http://www.w3school.com.cn/sql/func_dateadd.asp
阅读全文
摘要:1、创建事务的结构SqlConnection sqlConnection = new SqlConnection(); ...初始化连接 // 开启事务 SqlTransaction sqlTransaction = sqlConnection.BeginTransaction(); // 将事务应用于Command SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = sqlConnection; s...
阅读全文
摘要:今天由于工作需要,了解了下sql的多键组合唯一,打个比方Id1 Id21 2 可以13 可以2 2 可以1 2 不行因为和第一条的组合重复方法一、在sqlserver中选中需要进行组合判断的列然后右键 索引/键→添加→在索引/键面板的右边的编辑区的列中选择需要判断的列,然后把列下面的是唯一的选为是就可以了。方法二、alter table 表名 drop 索引名create unique nonclustered index [索引名称] on TTT (列一 asc,列二 asc ) go如果大家有更好的方法欢迎补充
阅读全文

浙公网安备 33010602011771号