sql-server-2012

nHibernate and SQL Server 2012 LocalDB

爷,独闯天下 提交于 2019-12-23 09:25:53
问题 Is it possible to use LocalDB databases with NHibernate? If yes, what should be installed/configured? Currently when trying to use connection string like Data Source=(LocalDb)\v11.0;Initial Catalog=tst1;Integrated Security=SSPI when creating SessionFactory I get System.Data.SqlClient.SqlException : A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and

How to INSERT into a table that uses sequential GUIDs as a primary key?

三世轮回 提交于 2019-12-23 09:01:28
问题 Here is a simplified version of the table I am looking at: CREATE TABLE [dbo].[FrustratingTable] ( [Id] Uniqueidentifier NOT NULL , [SecondField] [datetime] , [ThirdField] varchar(128) ) I want to insert new records into this table. I have tried 3 approaches: INSERT INTO [dbo].[FrustratingTable] (Id, SecondField, ThirdField) SELECT newid() as Id, '6/25/2015' as SecondField, 'Example' as ThirdField This approach inserts, but the resulting key isn't a nice sequential GUID like the other ones in

Why can I not find a foreign key using the OBJECT_ID() function?

送分小仙女□ 提交于 2019-12-23 08:58:27
问题 I have a strange issue in MS SQL Server 2012. I'm trying to check if a foreign key already exist in an upgrade script. I've used the system OBJECT_ID() function in the past to find tables, views and procedures, but when I try to use it to find a foreign key it does not work. -- This query always returns null SELECT OBJECT_ID(N'FK_Name', N'F') -- This query works, returning the object ID for the foreign key SELECT object_id FROM sys.foreign_keys WHERE name=N'FK_Name' This SO answer suggests

Master Table Node missing

百般思念 提交于 2019-12-23 08:54:00
问题 I've installed Micrososoft SQL Server 2012 Express. When I launch Managament Studio, I can't view any "table node" on System database.. Is it a bug? 回答1: It's a bug as mentioned at following link: http://connect.microsoft.com/SQLServer/feedback/details/773184/ssms-system-databases-node-does-not-show-tables 来源: https://stackoverflow.com/questions/16591194/master-table-node-missing

Case statement to determine if I should union

我的梦境 提交于 2019-12-23 07:57:54
问题 I currently want to do some sort of conditional union. Given the following example: SELECT age, name FROM users UNION SELECT 25 AS age, 'Betty' AS name Say I wanted to only union the second statement if the count of 'users' was >=2 , otherwise do not union the two. In summary I want to append a table with a row if the table only has 2 or more values. 回答1: You could use an ugly hack something like this, but I think Tim's answer is better: SELECT age, name FROM users UNION ALL SELECT 25 AS age,

Is there a function in Entity Framework that translates to the RANK() function in SQL?

风格不统一 提交于 2019-12-23 07:27:47
问题 Let's say I want to rank my customer database by country. In SQL I would write: select CountryID, CustomerCount = count(*), [Rank] = RANK() over (order by count(*) desc) from Customer Now I want to write this in Entity Framework: var ranks = db.Customers .GroupBy(c => c.CountryID) .OrderByDescending(g => g.Count()) .Select((g, index) => new {CountryID = g.Key, CustomerCount = g.Count, Rank = index+1}); There are two problems with this: It doesn't work. EF throws a System.NotSupportedException

Why working directory is changing when executing Invoke-sqlcmd?

廉价感情. 提交于 2019-12-23 07:08:33
问题 I am trying to search whether particualr machine name is there in database and if so we are replacing with new machine name. We are using powershell Add-pssnapin sqlserverprovidersnapin100 -ErrorAction SilentlyContinue Add-pssnapin sqlservercmdletsnapin100 -ErrorAction SilentlyContinue $SelectQuery = "SELECT [$columnName] FROM [$DatabaseName].[dbo].[$TableName] Where [$columnName] is not null;" try { $Qresult= Invoke-sqlcmd -query $SelectQuery -Database $DatabaseName -ServerInstance

DT_Decimal Data Type Cutting off Decimal

我的未来我决定 提交于 2019-12-23 06:48:06
问题 I have a flat file source that grabs a decimal value for the column Note Amount. The Source system specifies that this is a DECIMAL(12,2) file. I have the column in SSIS set to be DT_Decimal The particular Flat file has a value of 122735.13 for one of it's amounts. However if I place a data viewer on the flow after the source it seems to be cutting the decimal off. Any idea why this is happening? For reference I'm going to a Decimal(12,2) SQL Server 2012 Database. 回答1: Well it was pointed out

Insert issue Msg 213, Level 16, State 1, Line 2

牧云@^-^@ 提交于 2019-12-23 05:16:05
问题 General newbie SQL question probs... Why doesn't this work - or, what does this mean? INSERT INTO test_db.dbo.Customers2 SELECT FirstName FROM jas_test_db.dbo.Customers WHERE (Customers.FirstName = Firstname) I get: Msg 213, Level 16, State 1, Line 2 Column name or number of supplied values does not match table definition. 回答1: You should supply column name for Customers2: INSERT INTO test_db.dbo.Customers2(**Firstname**) SELECT FirstName FROM jas_test_db.dbo.Customers WHERE (Customers

Find the start and end of a redirect chain

吃可爱长大的小学妹 提交于 2019-12-23 05:13:58
问题 I have a table of URL redirects in a SQL server table, each redirect has an ID, a FromURL and a ToURL field. I've been asked to find where we have a chain of redirects in the table so that we can replace them with a single redirect so that users are only redirected once rather than multiple times. An example of the table is below: As you can see, if a user visits URL A, they will be redirected to B, then from B to C then from C to D we'd like to replace this with a single redirect from A to D