sql-server-2012

Unable to connect to SQL database - C#, VS2012, SQL Server 2012

浪子不回头ぞ 提交于 2019-12-20 06:46:46
问题 I have SQL Server 2005, 2008 and 2012 installed on my Windows 7 64bit PC. Here is my Configuration Manager, and I do see that the Agent is Stopped... not sure if this is required. I've split it out into two images so the size shows up larger Here is what is shown in the VS2012 Database Explorer window. This is a SQL Server 2012 database Here is my code string selectSql = "select * from Tasks"; string connectionString = "Data Source=adamssqlserver;Database=master;Integrated Security=True;";

Can I use one .mdf file with multiple DBMSes (SQL Server 2008 and 2012)?

时光怂恿深爱的人放手 提交于 2019-12-20 06:34:24
问题 At home, I have SQL Server 2008 R2 (Express) installed which is attached to a certain .mdf file. I'm in the process of installing SQL Server 2012 (Developer Edition). Can I attach 2012 to the same .mdf file? Logically, it seems like this would work as long as only one of the two instances of SQL Server is running. Thoughts? 回答1: You can go upwards - from an older version to a newer one, e.g. you can backup your database in 2008 R2 and restore that backup in your 2012 instance - but you CANNOT

Insert Into Table Variable CTE

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 03:18:09
问题 How to insert the results of a cte into a table variable Something like this? DECLARE @myData TABLE( Title nvarchar(350) NOT NULL , Id int NOT NULL , ); INSERT INTO @myData with CTE as (SELECT a.Title ,a.Id FROM TableA ) ,CTE2 as (SELECT b.Title ,b.Id FROM TableB ) Select * From CTE union all Select * From CTE2 Select ROW_NUMBER() OVER(ORDER BY GetDate() DESC) AS RowId , x.* From @myData x order by x.Id desc 回答1: Try this with CTE as (SELECT a.Title ,a.Id FROM TableA ) ,CTE2 as (SELECT b

Convert XML Nodes To Rows in SQL Server

不想你离开。 提交于 2019-12-20 02:58:25
问题 Consider the below sample: declare @somexml as xml set @somexml = ' <Settings> <Users> <ID>1</ID> <ID>2</ID> <ID>3</ID> <ID>4</ID> <ID>5</ID> </Users> </Settings>' The above XML has some ID values that I need to convert to rows of data that can be used in a temp table to perform joins against. I can't quite get the syntax correct, I've tried a number of samples that I've come across: SELECT T.r.value('.','int') as id FROM @somexml.nodes('/Settings/Users') T(r) Returns: |ID | |------| |12345 |

Will TSQL return faster results than stored procedure in SQL Server

与世无争的帅哥 提交于 2019-12-20 02:57:05
问题 I have a stored procedure that works fine previously. It took 4 to 5 secs to get the results. I didn't used this stored procedure for the past two months. When I call the same procedure now it takes more than 5 minutes to produce the result. (There is no records populated to my source tables in the past two months) I converted the stored procedure and executed as TSQL block it is back to normal. But when I convert back to stored procedure again it is taking more than 5 minutes. I am wondering

sql query xml values returning NULL

我怕爱的太早我们不能终老 提交于 2019-12-20 01:41:41
问题 I'm not experienced with the xml structure and need a start-point to how I can retrieve the values from xml structure below. I fetch the xml from a webservice using a stored-procedure and store to a table "StockInfoXML" Field in table holding the xml is XML_Url of type xml . <string xmlns="http://www.webserviceX.NET/"> <StockQuotes> <Stock> <Symbol>ENGI.PA</Symbol> <Last>13.53</Last> <Date>5/23/2017</Date> <Time>12:37pm</Time> <Change>+0.06</Change> <Open>13.45</Open> <High>13.59</High> <Low

Amazon RDS - are there workarounds to change a database time zone in SQL Server?

懵懂的女人 提交于 2019-12-19 23:58:21
问题 Amazon recently announced support for time zone change in Oracle RDS. Since this is still not supported for Microsoft SQL Server 2012, are there any workarounds, to obtain functionality similar to changing the whole database time zone? 回答1: Since you're asking for workarounds... We basically totally disregard server time/database time zone and work entirely off of UTC. GetUtcDate() for instance for all 'DateCreated' columns. Since we've committed to that approach we just don't bump up against

Export values from SQL Server to txt file

☆樱花仙子☆ 提交于 2019-12-19 19:53:10
问题 I want to export values from SQL Server to txt file. I know about BCP, there I need to give either query or table name to export data from a table. I don't want to export data but I want to export values that are assigned to variable. How can I do that, any help? 回答1: Use a query to collect the variables you want to export. Something like this: DECLARE @var1 INTEGER DECLARE @var2 INTEGER SELECT @var1 = 10 SELECT @var2 = 22 SELECT 'variable 1' AS VarName, @var1 AS VarValue UNION SELECT

NOCHECK does not disable foreign key references

徘徊边缘 提交于 2019-12-19 12:05:22
问题 Table creation script: CREATE TABLE [dbo].[details]( [id] [int] NULL, [details] [varchar](max) NULL ) CREATE TABLE [dbo].[name]( [id] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL, [name] [varchar](max) NULL, CONSTRAINT [PK__name__3213E83F0D384EE4] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] ALTER TABLE [dbo].[details] WITH NOCHECK

How can a Non-Clustered index output a column that is not included in the index

放肆的年华 提交于 2019-12-19 11:45:16
问题 Viewing the Execution plan, i see "column A" in the Output List. The operation is an Index Scan on a Non-Clustered Index : "IX_name" When i see the definition of this index. I do not see "column A" in either Index Key columns or Included columns. How is a Non-Clustered index being used to output a column that is not present in the index. Shouldn't it use a Table Scan on the table or some other index which has "column A" present in it. 回答1: If the table itself is clustered 1 , then all