sql-server-2005

Create a global static variable in SQL Server?

只愿长相守 提交于 2019-12-18 05:49:06
问题 Is there a way to create a global variable in SQL Server, in such a way that it persists even if the server is restarted, so I can use it in functions? Example from what I need: DECLARE @@DefaultValue bit This variable should never be deleted unless I explicityl do so. 回答1: I guess this will work the best for me: CREATE FUNCTION [dbo].[fn_GetDefaultPercent]() RETURNS decimal(5,4) AS BEGIN RETURN 1.0000 END 回答2: You can have a look at something like this "Global variables" in SQL Server 回答3:

Run db query (sql server 2005) with ajax. Is it possible?

守給你的承諾、 提交于 2019-12-18 05:25:21
问题 I never worked with ajax. I need to know if it is possible to use ajax to run a query on the db (sql server 2005). My target is to run a query with refreshing the page. Have you got any ideas? 回答1: As MarkusQ has said, it is not possible to do this directly, but you can call a web service or page method to perform the database query and return the result to the client side. Something like this for a Page Method (this is off the top of my head and untested. I'm also making the assumption you

Preserve parent-child relationships when copying hierarchical data

江枫思渺然 提交于 2019-12-18 05:06:29
问题 We have a table representing a tree of values associated with an entity (call it a project), where the ParentID column refers to the id column of a row's parent. The id column is an auto-incremented IDENTITY column and primary key. Root nodes have a ParentID of 0. We want to be able to clone the data for a given project and have the resulting ParentIDs refer to the appropriate new ids for the copied values, in a way that meets the restrictions described below the example. For example, copying

Can I set a default schema for within a stored procedure?

青春壹個敷衍的年華 提交于 2019-12-18 05:00:36
问题 I'm working on the next update for StackQL. One thing I want to do is have the ability to query over several releases. So when I loaded the October data, for example, I didn't delete the old September database. It's still out there. In fact, you can even still query it by including the database name like this: select top 10 * from SO_Sept09..Posts This will be even more important as they start providing data for ServerFault and SuperUser. But I don't like having a whole bunch of databases out

Recording SQL Server call stack when reporting errors

我只是一个虾纸丫 提交于 2019-12-18 04:54:26
问题 This is a follow up to the question Nested stored procedures containing TRY CATCH ROLLBACK pattern? In the catch block I use a stored procedure to report (reraise) the error by reading from ERROR_MESSAGE(), ERROR_PROCEDURE(), ERROR_LINE(), etc. As described here I also have a check so that it can determine if the error has already been rethrown (this happens with nested stored procedures as the error information is passed down through each TRY CATCH block). What I would like to do, either

TABLESAMPLE returns wrong number of rows?

泪湿孤枕 提交于 2019-12-18 04:42:25
问题 I've just discovered the TABLESAMPLE clause but surprisingly it doesn't return the number of rows i've specified. The table that i've used has ~14M rows and i wanted an arbitrary sample of 10000 rows. select * from tabData TABLESAMPLE(10000 ROWS) I get not 10000 but a different number everytime i execute it(between 8000 and 14000). What's going on here, have i misunderstood the intended purpose of TABLESAMPLE ? Edit : David's link explains it pretty well. This returns always 10000 roughly

Implications of nvarchar (50) vs nvarchar (max)

不羁岁月 提交于 2019-12-18 04:34:32
问题 What are the general storage and performance differences between the below two tables if their only difference is nvarchar(50) vs. nvarchar(max) and the strings in each field range from 1 to 50 characters? This is in SQL Server 2005. TABLE 1 firstname nvarchar (50) lastname nvarchar (50) username nvarchar (50) TABLE 2 firstname nvarchar (max) lastname nvarchar (max) username nvarchar (max) 回答1: If you are guaranteed to have strings between 1 and 50 characters, then the same query run across

4 byte unsigned int in SQL Server?

谁都会走 提交于 2019-12-18 04:31:42
问题 Is there a 4 byte unsigned int data type in MS SQL Server? Am I forced to use a bigint? 回答1: It doesn't seem so. Here's an article describing how to create your own rules restricting an int to positive values. But that doesn't grant you positive values above 2^31-1 . http://www.julian-kuiters.id.au/article.php/sqlserver2005-unsigned-integer 回答2: Can you just add/subtract 2,147,483,648 (2^31) to the regular int ? (subtract on the way in, & add coming out) I know it sounds silly, but if you

Monitoring the progress of an SQL query in SQL SERVER

非 Y 不嫁゛ 提交于 2019-12-18 04:31:29
问题 I saw a similar question which asked how to monitor the progress of a backup/restore operation: Is there a SQL script that I can use to determine the progress of a SQL Server backup or restore process? I would like to know if there's a similar query/way to see how much time the query has left until it will end. For example, one query usually has an elapsed time of 5 minutes. I would like to know how much time is left until it will end DURING the query's execution. 回答1: There is no way to know

Can you have a Foreign Key onto a View of a Linked Server table in SQLServer 2k5?

瘦欲@ 提交于 2019-12-18 04:19:12
问题 I have a SQLServer with a linked server onto another database somewhere else. I have created a view on that linked server create view vw_foo as select [id], [name] from LINKEDSERVER.RemoteDatabase.dbo.tbl_bar I'd like to to the following alter table [baz] add foo_id int not null go alter table [baz] with check add constraint [fk1_baz_to_foo] foreign key([foo_id]) references [dbo].[vw_foo] ([id]) go But that generates the error: "Foreign key 'fk1_baz_to_foo' references object 'dbo.vw_foo'