sql-server-2008-r2

Is this a bug in MERGE, failing to implement FOREIGN KEY properly?

霸气de小男生 提交于 2019-11-30 08:34:57
I am using the following tables to implement subtypes, which is a very common approach: CREATE TABLE dbo.Vehicles( ID INT NOT NULL, [Type] VARCHAR(5) NOT NULL, CONSTRAINT Vehicles_PK PRIMARY KEY(ID), CONSTRAINT Vehicles_UNQ_ID_Type UNIQUE(ID, [Type]), CONSTRAINT Vehicles_CHK_ValidTypes CHECK([Type] IN ('Car', 'Truck')) ); GO CREATE TABLE dbo.Cars(ID INT NOT NULL, [Type] AS CAST('Car' AS VARCHAR(5)) PERSISTED, OtherData VARCHAR(10) NULL, CONSTRAINT Cars_PK PRIMARY KEY(ID), CONSTRAINT Cars_FK_Vehicles FOREIGN KEY(ID, [Type]) REFERENCES dbo.Vehicles(ID, [Type]) ); GO -- adding parent rows INSERT

JTDS driver not working for Sql Server 2008R2 and Denali Native SSPI library not loaded. Check the java.library.path system property

耗尽温柔 提交于 2019-11-30 08:31:44
问题 I am trying to connect Sql Server Data Base using windows authentication from my application using JTDS driver but i got following error SSO Failed: Native SSPI library not loaded. Check the java.library.path system property. Following are the scenarios where i tried to resolve but still something is missing.. i have added ntlmauth.dll in system directory and it works fine for Sql server 2005. But the same thing i tried for Sql Server 2008 R2 and Denali but it gives me the same error as i

How to update a varbinary field with a specific value?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 08:28:52
Basically I am trying to give a user a certain password so I can test some functionality on a system, as I only have our admin account and I can't play with that I am just picking a random account so I can do my testing. So here is my attempt at an update: UPDATE dbo.Login SET Salt=CAST('bPftidzyAQik' AS VARBINARY), Password=CAST('0x2B89C2954E18E15759545A421D243E251784FA009E46F7A163926247FDB945F85F095DBB1FFF5B2B43A6ADAE27B8C46E176902412C4F8943E39528FF94E0DD5B' AS VARBINARY) WHERE LoginID=10947 It runs fine however the code in the database looks japanese for one and the syntax for the other

How to permit a SQL Server user to insert/update/delete data, but not alter schema?

旧巷老猫 提交于 2019-11-30 08:27:59
My application (C#, ASP.Net) needs to insert, update and delete data in the DB, and run stored procedures. I need to prevent it from modifying the DB schema - no altering tables, creating or dropping, no changes to stored procedures. What permissions combination do I need to grant to the application user? Just 'select' isn't going to work, because it needs to insert/update/delete data in tables. How do I check permissions and access for a particular login? How do I grant or deny permissions and access for a login? I need to give permissions to a new user (login) to access only one database.

SQL Server Agent gives- Remote procedure call failed (0x800706be)

佐手、 提交于 2019-11-30 08:02:43
Does Anyone knows the solution to this problem m not being able to run the SQL Server Services. With all due respect, "Right click on configuration manager and run as administrator" is a bogus answer. I also have this problem with the following series of events: I download the Windows Azure SDK from here: http://www.windowsazure.com/en-us/develop/downloads/ , which installs SQL 2012 express; immediate I try to run SQL Server Configuration Manager, and the installation of SQL 2012 has broken it such that I get the "remote procedure call failed". That is true even if I "run as administrator".

'MOD' is not a recognized built-in function name

China☆狼群 提交于 2019-11-30 07:59:15
I wanted to use MOD function in SQL Server 2008R2 and followed this link but still got the message: 'MOD' is not a recognized built-in function name. DECLARE @m INT SET @m = MOD(321,11) SELECT @m Error: Msg 195, Level 15, State 10, Line 2 'MOD' is not a recognized built-in function name. Why I can't use this function from the link above? The MOD keyword only exists in the DAX language (tabular dimensional queries), not TSQL Use % instead. Ref: Modulo In TSQL, the modulo is done with a percent sign. SELECT 38 % 5 would give you the modulo 3 for your exact sample, it should be like this. DECLARE

How to prevent arithmetic overflow error when using SUM on INT column?

可紊 提交于 2019-11-30 07:59:08
I am using SQL Server 2008 R2 and I have an INT column where the data inserted never surpasses the max INT , but I have a query which uses the SUM function which when executed surpasses the max INT limit and throws the error mentioned in the title. I want to be able to execute this query without changing the column type from INT to BIGINT . Here is my query: SELECT UserId, SUM( PokemonExp ) AS TotalExp, MAX( PokemonLevel ) AS MaxPokeLevel FROM mytable GROUP BY UserId ORDER BY TotalExp DESC Note: The PokemonExp column is of type INT . Michał Powaga Type of expression in SUM determines return

Referencing a calculated column in the where clause SQL

我只是一个虾纸丫 提交于 2019-11-30 07:59:01
问题 This line of code is a snippet from my select statement. frdFreedays - DateDiff(dd,conReceiptToStock,GetDate()) As FreeDaysRemaining Below is a snippet from my where clause and frdFreedays - DateDiff(dd,conReceiptToStock,GetDate()) <= @intFreeDays The question I have is how can I reference the FreeDaysRemaining column and so I can compare it to @ intFreeDays I am looking for something like this Freedays <= @intFreeDays 回答1: In addition to Aaron's answer, you could use a common table

undocumented CONVERT styles - datetime 23

两盒软妹~` 提交于 2019-11-30 07:39:10
Recently I stumbled upon CONVERT function style 23, which is very handy as it gives you DATE in format yyyy-mm-dd . The problem is that it's not documented in msdn! (link from SSMS help after F1 on CONVERT: http://msdn.microsoft.com/en-us/library/ms187928%28SQL.105%29.aspx ). Example: select convert( date ,'2012-01-30', 23) select convert(varchar(255), getdate(), 23) This style is very useful and I've been missing it, but my concerns are: - Is it safe to use? Is it deprecated or sneak in by mistake and may be removed in future editions / updates? - Does anybody know of other hidden styles?

Finding rows with consecutive increase in the values of a column

淺唱寂寞╮ 提交于 2019-11-30 07:17:30
问题 I have a sql table that stores the daily prices of stocks. New records are inserted every day after the market closes. I want to find the stocks that have consecutive increases in price. The table has lots of columns, but this is the relevant subset: quoteid stockid closeprice createdate -------------------------------------------------- 1 1 1 01/01/2012 2 2 10 01/01/2012 3 3 15 01/01/2012 4 1 2 01/02/2012 5 2 11 01/02/2012 6 3 13 01/02/2012 7 1 5 01/03/2012 8 2 13 01/03/2012 9 3 17 01/03