我们正在处理需要处理来自不同时区和夏令时设置的全球时间数据的应用程序.我们的想法是在内部以UTC格式存储所有内容,只为本地化用户界面来回转换.SQL Server是否提供任何机制来处理给定时间,国家和时区的翻译?
这一定是一个常见的问题,所以我很惊讶谷歌不会发现任何可用的东西.
有什么指针吗?
愚蠢的问题 - 在我想用生产服务器中的实例刷新开发服务器的环境中复制实例的最佳方法是什么?
我已经完成了备份恢复,但是我听说了detach-copy-attach,一个人甚至告诉我他只会复制文件系统之间的数据文件....
这三种(或两种,最后一种听起来有点可疑)接受的方法是什么?
我的理解是第二种方法更快,但由于分离方面的原因需要在源上停机.
此外,在这种情况下(想要在开发服务器上获得精确的生产副本),传输登录等的公认惯例是什么?我应该只备份和恢复用户数据库+ master + msdb吗?
在后台究竟发生了什么使SQLParameter阻止了.NET参数化查询中的SQL Inection攻击?它只是剥离任何可疑的角色还是还有更多的东西?
有人在那里检查,看看当你传递恶意输入时实际上到达SQL Server的是什么?
我试图从我的C#windows应用程序调用存储过程.存储过程在SQL Server 2008的本地实例上运行.我能够调用存储过程但我无法从存储过程中检索该值.该存储过程应该返回序列中的下一个数字.我在网上做过研究,我见过的所有网站都指出这个解决方案有效.
存储过程代码:
ALTER procedure [dbo].[usp_GetNewSeqVal]
@SeqName nvarchar(255)
as
begin
declare @NewSeqVal int
set NOCOUNT ON
update AllSequences
set @NewSeqVal = CurrVal = CurrVal+Incr
where SeqName = @SeqName
if @@rowcount = 0 begin
print 'Sequence does not exist'
return
end
return @NewSeqVal
end
Run Code Online (Sandbox Code Playgroud)
调用存储过程的代码:
SqlConnection conn = new SqlConnection(getConnectionString());
conn.Open();
SqlCommand cmd = new SqlCommand(parameterStatement.getQuery(), conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter();
param = cmd.Parameters.Add("@SeqName", SqlDbType.NVarChar);
param.Direction = ParameterDirection.Input;
param.Value = "SeqName";
SqlDataReader reader = cmd.ExecuteReader();
Run Code Online (Sandbox Code Playgroud)
我也尝试使用a …
我有一个数据库,[我的数据库],它有以下信息:
SQL Server 2008
MDF大小:30 GB
LDF大小:67 GB
我想尽可能地缩小日志文件,所以我开始寻找如何做到这一点.警告:我不是一名DBA(甚至是接近DBA)并且一直在通过这个任务感受到进步.
首先,我刚进入SSMS,数据库属性,文件,并将初始大小(MB)值编辑为10.这将日志文件减少到62 GB(不完全是我输入的10 MB).所以,我附加了SQL Profiler,看到正在调用DBCC SHRINKFILE.然后我将该命令输入查询编辑器,这是结果.
DBCC SHRINKFILE (N'My DB_Log' , 10)
Run Code Online (Sandbox Code Playgroud)
输出是:
Cannot shrink log file 2 (My DB_Log) because the logical log file located at the end of the file is in use.
DbId FileId CurrentSize MinimumSize UsedPages EstimatedPages
------ ----------- ----------- ----------- ----------- --------------
8 2 8044104 12800 8044104 12800
(1 row(s) affected)
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Run Code Online (Sandbox Code Playgroud)
然后我做了一些研究,发现了这个:
http://support.microsoft.com/kb/907511
这说我需要在收缩文件之前备份日志文件,以便释放虚拟日志文件并且收缩文件可以完成它的工作 - …
我试图覆盖SqlConnection15秒的默认超时,并得到一个错误说
无法分配属性或索引器,因为它是只读的.
有没有解决的办法?
using (SqlConnection connection = new SqlConnection(Database.EstimatorConnection))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
connection.ConnectionTimeout = 180; // This is not working
command.CommandText = "sproc_StoreData";
command.Parameters.AddWithValue("@TaskPlanID", order.Projects[0].TaskPlanID);
command.Parameters.AddWithValue("@AsOfDate", order.IncurDate);
command.ExecuteNonQuery();
}
}
Run Code Online (Sandbox Code Playgroud) 我RANK()在SQL Server中使用时遇到问题.
这是我的代码:
SELECT contendernum,
totals,
RANK() OVER (PARTITION BY ContenderNum ORDER BY totals ASC) AS xRank
FROM (
SELECT ContenderNum,
SUM(Criteria1+Criteria2+Criteria3+Criteria4) AS totals
FROM Cat1GroupImpersonation
GROUP BY ContenderNum
) AS a
Run Code Online (Sandbox Code Playgroud)
该查询的结果是:
contendernum totals xRank
1 196 1
2 181 1
3 192 1
4 181 1
5 179 1
Run Code Online (Sandbox Code Playgroud)
我想要的结果是什么:
contendernum totals xRank
1 196 1
2 181 3
3 192 2
4 181 3
5 179 4
Run Code Online (Sandbox Code Playgroud)
我想根据结果对结果进行排名totals.如果有相同的值181,那么两个数字将具有相同的值xRank.
如何从日期字段中按月分组(而不是按日分组)?
这是我的日期字段的样子:
2012-05-01
Run Code Online (Sandbox Code Playgroud)
这是我目前的SQL:
select Closing_Date, Category, COUNT(Status)TotalCount from MyTable
where Closing_Date >= '2012-02-01' and Closing_Date <= '2012-12-31'
and Defect_Status1 is not null
group by Closing_Date, Category
Run Code Online (Sandbox Code Playgroud) 我想B在我的下面的SQL中显示该列,但是当我将它添加到查询时它会给我以下错误:
列T2.B'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中.
我的代码:
SELECT A, COUNT(B) as T1, B
FROM T2
WHERE ID=1
GROUP BY A
Run Code Online (Sandbox Code Playgroud) 我正在遵循Code First到现有数据库教程,并注意到它建议连接到(localdb)\v11.0学习目的.我尝试使用我的SQL Management Studio连接到它,它工作正常.但是当我恢复数据库备份时,它[DatabaseName].mdf在我的用户目录中创建了一个文件.
我很惊讶并有以下问题:
(localdb)\v11.0?它使用我的SQL Express还是SQL Compact?.mdf文件中的数据库?