我们刚刚发现了另一台带有数据库的服务器。数据库归 SQL 帐户所有SA,具有public和sysadmin角色。另一个登录名是BUILTIN\Users,只有public。我只能通过这个连接。SA是disabled,即使不是,我们也可能不知道密码。
问题:有什么方法可以使用enable SA或创建另一个 sql 登录sysadmin?
我在 SQL Server 2008 R2 上的完整恢复模型中有一个简单的数据库备份脚本:
backup database livendb to disk = '\\ehsjmaydb01\Data\livendb.bak' with init, format
backup log livendb to disk = '\\ehsjmaydb01\Data\livendb_log.tran' with init, format
Run Code Online (Sandbox Code Playgroud)
我们在周末打开了一个新的 ETL 脚本,这绝对让我糟糕的服务器崩溃了。事务日志已满,TempDB 已满。
查看我的备份作业的历史记录,它失败并显示以下消息:
数据库“liveendb”的事务日志已满。
要找出无法重用日志中的空间的原因,请参阅 sys.databases
[SQLSTATE 42000] (Error 9002) BACKUP DATABASE is termination异常中的 log_reuse_wait_desc 列。
[SQLSTATE 42000](错误 3013)。步骤失败。
当我来到这个早上,我能够备份日志第一,然后运行DB备份,而这工作得很好。
问题:为什么数据库备份过程需要日志文件中的空间?
我们的 sql server 迁移被延迟(自然地),并且在新的切换日期之前它将用完空间。为了保持数据库正常运行,我需要给它另一个数据库文件来开始写入。
我已经分配了空间并准备好了,但是当我创建它时,SQL Server 会立即开始将数据移动到新文件中吗?
问题:我最好创建两个新文件,然后运行
dbcc shrinkfile (livendb, emptyfile)
Run Code Online (Sandbox Code Playgroud)
在旧的?确保他们立即变得平等?
我的最终目标是将前几年的钱计算为 2019 美元。
我从 BLS 获得了这些数字,并在 sql 中创建了 CPI_U,如下所示:
create table CPI_U (year int, dec decimal(4,2), annual_avg decimal(4,2))
insert into CPI_U (year, dec, annual_avg)
values
(2000, 3.4,3.4),
(2001, 1.6,2.8),
(2002, 2.4,1.6),
(2003, 1.9,2.3),
(2004, 3.3,2.7),
(2005, 3.4,3.4),
(2006, 2.5,3.2),
(2007, 4.1,2.8),
(2008, 0.1,3.8),
(2009, 2.7,-0.4),
(2010, 1.5,1.6),
(2011, 3.0,3.2),
(2012, 1.7,2.1),
(2013, 1.5,1.5),
(2014, 0.8,1.6),
(2015, 0.7,0.1),
(2016, 2.1,1.3),
(2017, 2.1,2.1),
(2018, 1.9,2.4)
Run Code Online (Sandbox Code Playgroud)
然后我像这样构建一个三角形:
with cpi_triangle as (
select c1.year, c1.dec as c1, c2.dec as c2, c3.dec as c3, c4.dec …Run Code Online (Sandbox Code Playgroud) 我没有构建它,但我们有一个 32 位的 Windows Server 2008,带有 SQL Server 2008 和 4GB 的 RAM。
我需要将它升级到 SQL Server 2016,以便将日志传送到新服务器,这样我们就可以摆脱困境。
问题 - 看起来 SQL Server 2016 至少需要 Windows Server 2012,它只有 64 位。
问题:如何将数据迁移到 SQL 2016 服务器,停机时间小于 1 天?
有没有办法通过兼容性级别来解决它?
不幸的是,我无法备份和恢复,因为新数据库使用的是旧版本的 SQL。
当我运行以下脚本时,出现此错误:
Msg 117, Level 15, State 1, Line 1
The object name 'eih-dr01.eih.ehs.org.DBA.dbo.fp_monthly' contains more than the maximum number of prefixes. The maximum is 2.
Run Code Online (Sandbox Code Playgroud)
declare @table varchar(255),
@sql nvarchar(max)
declare c cursor local for
select st.name from sys.tables st
open c
fetch next from c into @table
set @sql = 'select * into [eih-dr01.eih.ehs.org].DBA.dbo.' + @table + ' from ' + @table
print @sql
exec sp_executesql @sql
fetch next from c into @table
close c
deallocate c …Run Code Online (Sandbox Code Playgroud) 我遇到了一些奇怪的行为:在将浮点值传递到 varchar 列时,这些值正在从整数转换为科学记数法,而正是这种科学记数法存储为字符串。
if OBJECT_Id('tempdb..#whydis') is not null begin drop table #whydis end
if OBJECT_Id('tempdb..#ImSeriously') is not null begin drop table #ImSeriously end
create table #whydis (bigID float)
create table #ImSeriously (bigID varchar(255))
insert into #whydis(BigID)
values(1495591),
(1495289),
(1495610),
(1495611),
(1495609),
(1495592),
(1495686)
INSERT INTO #ImSeriously (bigID)
SELECT BigID from #whydis
select * from #ImSeriously
Run Code Online (Sandbox Code Playgroud)
结果如下所示:
1.49559e+006
以字符串形式存储的科学记数法。通过转换为 int 很容易解决:
INSERT INTO #ImSeriously (bigID)
SELECT cast(BigID as int) from #whydis
Run Code Online (Sandbox Code Playgroud)
但整件事让我摸不着头脑。
问题:以这种方式存储它们的浮点数是怎么回事?