sql-server-2005

What to do when I want to use database constraints but only mark as deleted instead of deleting?

放肆的年华 提交于 2019-12-18 13:33:25
问题 I am working in a project where database items are not deleted, but only marked as deleted. Something like this: id name deleted --- ------- -------- 1 Thingy1 0 2 Thingy2 0 3 Thingy3 0 I would like to be able to define something like a UNIQUE constraint on the name column. Seems easy, right? Let's imagine a scenario in which "Thingy3" is deleted, and a new one is created (perhaps years later). We get: id name deleted --- ------- -------- 1 Thingy1 0 2 Thingy2 0 3 Thingy3 1 ... 100 Thingy3 0

inner join Vs scalar Function

﹥>﹥吖頭↗ 提交于 2019-12-18 13:07:26
问题 Which of the following query is better... This is just an example, there are numerous situations, where I want the user name to be displayed instead of UserID Select EmailDate, B.EmployeeName as [UserName], EmailSubject from Trn_Misc_Email as A inner join Mst_Users as B on A.CreatedUserID = B.EmployeeLoginName or Select EmailDate, GetUserName(CreatedUserID) as [UserName], EmailSubject from Trn_Misc_Email If there is no performance benefit in using the First, I would prefer using the second...

SQL Server 2005:charindex starting from the end

纵饮孤独 提交于 2019-12-18 12:58:19
问题 I have a string 'some.file.name',I want to grab 'some.file'. To do that,I need to find the last occurrence of '.' in a string. My solution is : declare @someStr varchar(20) declare @reversedStr varchar(20) declare @index int set @someStr = '001.002.003' set @reversedStr = reverse(@someStr) set @index = len(@someStr) - charindex('.',@reversedStr) select left(@someStr,@index) Well,isn't it too complicated?I was just intented to using 'some.file' in a where-clause. Anyone has a good idea? 回答1:

Debugging stored procedures in SQL Server Management Studio

﹥>﹥吖頭↗ 提交于 2019-12-18 12:44:52
问题 Is there a way to step into the stored procedure code in SQL Server Management Studio? I know this is possible with Visual Studio, but I am looking for a dependable debugging solution from within Management Studio 回答1: Only with SQL 2008 and SSMS 2008. Select from menu 'Debug\Start Debugging' or press Alt+F5 and will launch the step by step T-SQL debugger. On 2005 the only way is to attach Profiler and monitor for the SP:StmtCompleted event, which is not exactly debugger step-by-step, but at

SQL Server connection to node js

烂漫一生 提交于 2019-12-18 12:28:40
问题 I am trying to establish a connection between nodejs project and server running Microsoft SQL Server 2005. I am using a node module mssql , but I get these errors when I am attempting to create a connection: { [ConnectionError: Failed to connect to 123.123.12.1:1433 in 15000ms] name: 'ConnectionError', message: 'Failed to connect to 123.123.12.1:1433 in 15000ms', code: 'ETIMEOUT' } My connection being made by var sql = require('mssql'); var dbConfig = { server:'123.123.12.1', database:

SQL Server 2005 Get First and Last date for any Month in any Year

泄露秘密 提交于 2019-12-18 12:26:20
问题 I have a stored procedure that has to accept a month as int (1-12) and a year as int. Given those two values, I have to determine the date range of that month. So I need a datetime variable to represent the first day of that month, and another datetime variable to represent the last day of that month. Is there a fairly easy way to get this info? 回答1: DECLARE @Month int DECLARE @Year int set @Month = 2 set @Year = 2004 select DATEADD(month,@Month-1,DATEADD(year,@Year-1900,0)) /*First*/ select

Multiple Primary Key with asp .net mvc 3

拟墨画扇 提交于 2019-12-18 12:04:32
问题 I'm using asp .net mvc 3, and I have a problem with an entity that contains 2 primary key, when I try to insert data in the table. public class LineItem { [Key] public int OrderId { get; set;} [Key] public int LineNum { get; set;} public string ItemId { get; set;} public int Quantity { get; set;} public decimal UnitPrice { get; set; } } when I try to insert I got this error : Unable to determine composite primary key ordering for type 'ApplicationMVC3.Models.LineItem'. Use the ColumnAttribute

How to remove diagramming support objects from SQL Server?

旧巷老猫 提交于 2019-12-18 11:53:04
问题 I need to remove diagramming support tables, stored procs, views, etc from SQL Servrer using TSQL script. Is there such a script available? SQL 2005 and 2008. 回答1: You can drop the objects, but a user will be prompted to recreate them when they click the diagrams node. Objects: sp_upgraddiagrams sp_helpdiagrams sp_helpdiagramdefinition sp_creatediagram sp_renamediagram sp_alterdiagram sp_dropdiagram fn_diagramobjects sysdiagrams dt_properties (?) 回答2: DROP PROCEDURE dbo.sp_alterdiagram; DROP

Log4net not inserting into the database?

前提是你 提交于 2019-12-18 11:45:59
问题 I have log4net setup and configured to insert into a sql server 2005 table. My table is called Log. When I call the log4net method it does not enter any data into the log database in sql server. I am not getting any errors from my client c# code. Do I need to add a user to the log table in sql? Right now I am using windows authentication. <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name=

How to change the language and date format in SQL Server?

谁说我不能喝 提交于 2019-12-18 11:33:25
问题 I am using SQL Server 2005. When I execute DBCC USEROPTIONS , I see the language as romana and dateformat as dmy . I want the language to be us_english and dateformat as mdy . How can I do this? I was having these settings initially but somehow they got changed to romana. How to revert back to us_english and date as dmy ? 回答1: You can reset the language by using the below syntax set language 'us_english' In order to view all the languages and their date format try this one select * from sys