sql-server

Finding a Identity Specification using SQL

Good Morning, I have a SQL Server database, of which there is a column that has an identity specification. However, if I do a SQL query such as: SELECT * FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = It doesn't tell me if the column is an identity specification - is there a query that will? Many Thanks, Joel ...

SQL syntax error

Im using Microsoft SQL Server which I think is T-SQL or ANSI SQL. I want to search a database with a string. The matches that fit the begging of the string should come first then sort alphabetically. I.e. If the table contains FOO, BAR and RAP a search for the string 'R' should yield: RAP BAR In that order. Here is my attempt: S...

Can I create a table with check constrain whose values are dependent on sql query

Is it possible to create a table which has a check constraint on one of the column whose value lies within the result set given by another sql query eg. create table tablename ( name varchar(10), rollno int )check rollno in (select rollno from anotherDatabase.TableName,candidateRoll) or any thing like that. I dont have to use it an...

How to create the initial database on deployment?

If I have a Silverlight application, and I am publishing to my localhost IIS server with the web deploy option: Can my database be automatically created in SQL Server Express? I'm not talking about creating tables and columns etc, i'm talking about creating the actual database at the destination. How would I do that? ...

Statistical analysis for performance measurement on usage of bigger datatype wherever they were not required at all

If i takes larger datatype where i know i should have taken datatype that was sufficient for possible values that i will insert into a table will affect any performance in sql server in terms of speed or any other way. eg. IsActive (0,1,2,3) not more than 3 in any case. I know i must take tinyint but due to some reasons consider...

question in sql server 2005 Proc

i have this Proc CREATE Proc [dbo].Salse_Ditail -- Add the parameters for the stored procedure here @Report_Form varchar(1) , @DateFrom datetime , @DateTo datetime , @COMPANYID varchar(3), @All varchar(1) , @All1 varchar(1) , @All2 varchar(1) , @All3 varchar(1) , @All4 varchar(...

What to monitor on SQL Server

Hi all I have been asked to monitor SQL Server (2005 & 2008) and am wondering what are good metrics to look at? I can access WMI counters but am slightly lost as to how much depth is going to be useful. Currently I have on my list: user connections logins per second latch waits per second total latch wait time dead locks per second ...

SQL Server user best practice

Hi, I have a login with Windows Authentication which is called domain\username. Now I want to map this login to my DB and the SSMS is proposing a user called domain\username as well. I don't know if I have to map the domain login to the database user as domain\username or simply as username. What is the best practice? THANKS ...

Is it a problem if i query again and again to SQL Server 2005 and 2000?

Window app i am constructing is for very low end machines (Celeron with max 128 RAM). From the following two approaches which one is the best (I don't want that application becomes memory hog for low end machines):- Approach One:- Query the database Select GUID from Table1 where DateTime <= @givendate which is returning me more than 30...

Authenticating SQL connection using certificates in .NET

I've noticed that it is possible SQL Server 2005/2008 to authenticate replication accounts using certificates. Is it possible to authenticate .NET SqlConnection in the same manor? Ideally, I'd like to do away with password authentication completely and have the aspnet user connect using a certificate stored against its account. Is thi...

Is there an equivalent to PostgreSQL's WildSpeed for Sql Server?

Wildspeed: http://www.sai.msu.su/~megera/wiki/wildspeed Looks like a great way to do Like '%term%' matching in a fast efficient way, albeit with huge indexes. I'm looking for something similar for Sql Server. Full Text Search is not working for partial word matches, so please don't suggest that unless you have a way to use Full Text ...

How does one SELECT block another?

I'm looking at output of SP_WhoIsActive on SQL Server 2005, and it's telling me one session is blocking another - fine. However they both are running a SELECT. How does one SELECT block another? Shouldn't they both be acquiring shared locks (which are compatible with one another)? Some more details: Neither session has an open transa...

SQL Server 2008 Management Studio Basic and Express

Hi, what are the differences between the SQL Server 2008 Management Studio BASIC and SQL Server 2008 Management Studio EXPRESS? Do they are the same? THANKS! ...

where to add a COLLATION in an SPROC

i've got a collation error happening in a stored procedure in SQL Server. Cannot resolve the collation conflict between "Latin1_General_CS_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation. The database's collation is Latin1_General_CS_AS The error happens on the INSERT INTO line. Where should i add a COLLATE statement...

Varchar columns: Nullable or not.

The database development standards in our organization state the varchar fields should not allow null values. They should have a default value of an empty string (""). I know this makes querying and concatenation easier, but today, one of my coworkers questioned me about why that standard only existed for varchar types an not other dat...

Query performs poorly unless a temp table is used

The following query takes about 1 minute to run, and has the following IO statistics: SELECT T.RGN, T.CD, T.FUND_CD, T.TRDT, SUM(T2.UNITS) AS TotalUnits FROM dbo.TRANS AS T JOIN dbo.TRANS AS T2 ON T2.RGN=T.RGN AND T2.CD=T.CD AND T2.FUND_CD=T.FUND_CD AND T2.TRDT<=T.TRDT JOIN TASK_REQUESTS AS T3 ON T3.CD=T.CD AND T3.RGN=T.RGN AND T3.TASK ...

How to find level of employee position using RECURSIVE COMMON TABLE EXPRESSION

;with Ranked(Empid,Mngrid,Empnm,RN,level) As (select Empid,Mngrid ,Empnm ,row_number() over (order by Empid)AS RN , 0 as level from dbo.EmpMngr), AnchorRanked(Empid,Mngrid,Empnm,RN,level) AS(select Empid,Mngrid,Empnm,RN ,level from Ranked ), RecurRanked(Empid,Mngrid,Empnm,RN,level) AS(select Empid,Mn...

Getting date string from getdate method

Hi, I need date string using sql statement like.. select getDate() this will return 2010-06-08 16:31:47.667 but I need in this format 201006081631 = yyyymmddhoursmin How can I get this? Thanks ...

I need to remove a unique constraints that I don't know the names of

I maintain a product that is installed at multiple locations which as been haphazardly upgraded. Unique constraints were added to a number of tables, but I have no idea what the names are at any particular instance. What I do know is the table/columnname pair that has the unique constraints and I would like to write a script to delete an...

Comparison to insert into query is better

Which one of below query has better performance? What's the upside/downside for both query? I want to discuss the scenario for inserting 1000 rows and 100k rows Thanks. 1st INSERT INTO table_name (col1,col2) VALUES (value1, value2); INSERT INTO table_name (col1,col2) VALUES (value3, value4); 2nd INSERT INTO table_name SELECT (col1,c...