sql-server-2008-r2

Hiding databases for a login on Microsoft Sql Server 2008R2 and above [closed]

限于喜欢 提交于 2019-12-31 14:46:34
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Please can anyone assist with hiding the available databases on sql server 2008R2 or newer versions. I have a new login user that I mapped to a specific database. When logging in with the specific login user I can see all the databases on the server, although I cannot access them except for the one I mapped to

Unique key vs. unique index on SQL Server 2008

☆樱花仙子☆ 提交于 2019-12-31 08:52:12
问题 I have a table called countries and I define the country_name column to be unique by creating a “Index/Key” of type “Unique Key” on SQL Server 2008 R2. But I have the following questions: will creating “Index/Key” of type “Unique Key” automatically create a non-clustered index on this column? if I change the type from being “Unique Key” to "Index" and I keep the IsUnique value to be "Yes",, then will there be any differences ? so why there are two options “Unique Key” and "Index" I think the

Pivot in SQL 2008 R2

只愿长相守 提交于 2019-12-31 07:41:44
问题 I have table like this; Date PlacementName campaignID Impressions Clicks TotalConversions Activity 01/01/2014 USA 100 5000 500 50 Mobile Book 01/02/2014 U.K 101 7000 250 30 Mobile Book 01/01/2014 USA 100 9000 800 40 Mobile TV 01/02/2014 U.K 101 6000 300 10 Mobile TV I want to pivot table for 15-20 Activity from the real table because this is just example table. I want my table look like below; Date PlacementName CampaignID Impressions Clicks Mobile Book Mobile TV 01/01/2014 USA 100 5000 500

Pivot in SQL 2008 R2

馋奶兔 提交于 2019-12-31 07:41:06
问题 I have table like this; Date PlacementName campaignID Impressions Clicks TotalConversions Activity 01/01/2014 USA 100 5000 500 50 Mobile Book 01/02/2014 U.K 101 7000 250 30 Mobile Book 01/01/2014 USA 100 9000 800 40 Mobile TV 01/02/2014 U.K 101 6000 300 10 Mobile TV I want to pivot table for 15-20 Activity from the real table because this is just example table. I want my table look like below; Date PlacementName CampaignID Impressions Clicks Mobile Book Mobile TV 01/01/2014 USA 100 5000 500

Check if SQL object is referenced by any other SQL objects

孤者浪人 提交于 2019-12-31 06:13:08
问题 I was just reading this SO thread and had a question for @Mack regarding whether there is a way to check if a SQL object is referenced by any other SQL objects. He (@Mack) used T-SQL and DMVs to accomplish something similar in his answer. Is this possible, if so how? I would have posted this as a comment, but I don't have sufficient reputation yet... 回答1: You can, but not with a DMV instead you'll need a related dynamic management function (DMF) dm_sql_referencing_entities (more info here).

Writing data to text file using BCP prompts for file storage type

核能气质少年 提交于 2019-12-31 04:39:07
问题 I'm copying data from SQL to text file using bcp tool with following command: bcp.exe "exec <StoredProcedure>" queryout "temp.txt" -T -r\n -c This command runs as expected on test environment and creates/updates required file without additional prompts. But when it's run in client's environment, bcp additionally prompts for field length, prefix and field terminator- so when command is run from SQL Agent job, it get's stuck in infinite wait. Any ideas why is this happening? Based on bcp

how to read the content of xml file in the remote(network) machine through mssql stored procedures

五迷三道 提交于 2019-12-31 03:54:07
问题 I tried to read the contents of single xml file in the local machine using bulk insert. SELECT * FROM OPENROWSET ( BULK '''+ @FILENAME+''' , SINGLE_CLOB ) AS xmlData It is working, but the same i am trying to read from the remote machine. its giving the following error Msg 4861, Level 16, State 1, Line 1 Cannot bulk load because the file "Z:\TechnicalLoss_EnergyAccounting_10.10.2012.12.19.PM.XML" could not be opened. Operating system error code 3(The system cannot find the path specified.). i

How to find the Nearest (day of the week) for a given date

别来无恙 提交于 2019-12-31 03:40:47
问题 I been practicing queries, and my current scenario is to find the nearest Saturday for a given date. After i got the logic down, i came up with a, whats looks like a long and messy query. And I was wondering if there is a way to simplify this. Here's my query DECLARE @DATE DATE SET @DATE ='2013-09-13' IF DATENAME(DW,@DATE) = 'SUNDAY' BEGIN SELECT DATEADD(DAY,-1,@DATE) AS DATE, 'IS THE NEAREST SATURDAY' END ELSE IF DATENAME(DW,@DATE) = 'MONDAY' BEGIN SELECT DATEADD(DAY,-2,@DATE) AS DATE, 'IS

Why are lock hints needed on an atomic statement?

北城余情 提交于 2019-12-31 01:53:06
问题 Question What is the benefit of applying locks to the below statement? Similarly, what issue would we see if we didn't include these hints? i.e. Do they prevent a race condition, improve performance, or maybe something else? Asking as perhaps they're included to prevent some issue I've not considered rather than the race condition I'd assumed. NB: This is an overflow from a question asked here: SQL Threadsafe UPDATE TOP 1 for FIFO Queue The Statement In Question WITH nextRecordToProcess AS (

Simple dynamic TSQL query syntax

前提是你 提交于 2019-12-30 06:24:28
问题 This may be an easy answer but I've been staring at it for too long... I have the following query that takes a stored procedure input parameter as a variable name and counts the records in that table. I'd like to retrieve the results of the dynamic statement (@toStartStr) into a variable (@toStart). -- @tempTableName = SProc input parameter DECLARE @toStartStr nvarchar(150); DECLARE @toStart int; SET @toStartStr = 'SELECT @toStart = COUNT(ID) FROM ' + @tempTableName; EXEC(@toStartStr); Right