sql-server-2005

Foreign key referencing a 2 columns primary key in SQL Server

This question is pretty much similar to this one, but for SQL Server 2005 : I have 2 tables in my database: --'#' denotes the primary key [Libraries] #ID #Application Name 1 MyApp Title 1 2 MyApp Title 2 [Content] #ID Application LibraryID Content 10 MyApp 1 xxx 11 MyApp 1 ...

Complex TSQL order by clause

Is it possible to craft an ORDER BY clause to ensure the following criteria for two fields (both of type INT), called child and parent respectively for this example. parent references child, but can be null. A parent can have multiple children; a child only one parent. A child cannot be a parent of itself. There must exist at least one...

sql query like this please help me to correctly form it thank you

select DISTINCT table0.person_name, table5.animal_name from table1 INNER JOIN table0, table5 on table1.person_id=table0.person_id and table1.animal_id=table5.animal_id where table1.aa=input1 and table1.bb=input2 and table1.cc=input3 and table1.dd=input4 2 base tables, 1...

How to run a select query on SQL Server 2005 without locking tables?

Is it sure for me to run a select query on SQL Server 2005 without locking the tables? Or can I get into troubles if some of the tables has exclusive locks? Will NO-LOCK syntax always be safe to use? What do you typically do? ...

how many joins can a sql query have

ANSWERER @MARK BYERS gave an answer to one of my questions, his answer is right to the best of my knowledge. here question to the answer is how many INNER JOIN s can a query tolerate SELECT table0.person_name, table5.animal_name FROM table1 JOIN table0 ON table1.person_id = table0.person_id JOIN table5 ON table1.animal_id = table5...

will this query alternative to join (simple) work?

the link is http://www.sqlcommands.net/sql+join/ i would like to know if it would work if it were SELECT Weather.City FROM Weather WHERE Weather.City = State.City meaning select all those cities "from weather" which belong in the state table will the above work if not then why? ...

SQL query executing slowly (for some parameter values)

I have a SQL Server 2005 database with several tables. One of the tables is used to store timestamps and message counters for several devices, and has the following columns: CREATE TABLE [dbo].[Timestamps] ( [Id] [uniqueidentifier] NOT NULL, [MessageCounter] [bigint] NULL, [TimeReceived] [bigint] NULL, [DeviceTime] [bigint] NULL, [Devic...

What is wrong with this sample query?

SELECT table0.person_name, table5.animal_name FROM table1 JOIN table0 ON table1.person_id = table0.person_id JOIN table5 ON table1.animal_id = table5.animal_id WHERE table1.aa = input1 AND table1.bb = input2 AND table1.cc = input3 AND table1.dd = input4 an answerer said If you ever even get close, you're doing it wrong :) ...

Retrieveing the most recent records within a query

I have the following tables: tblPerson: PersonID | Name --------------------- 1 | John Smith 2 | Jane Doe 3 | David Hoshi tblLocation: LocationID | Timestamp | PersonID | X | Y | Z | More Columns... --------------------------------------------------------------- 40 | Jan. 1st | 3 | 0 | 0 | 0 | M...

Date time string insert to db

Hi I am trying to insert the following to SQL Server 2005: INSERT INTO tb_UserLoginTimes (UserID, LoginDateTime) VALUES (1235,2010/07/06 10:38:44) But am getting the following error. Incorrect syntax near '10'. Do I need to escape the colon? If so how do I do that? Real noob at this so my apologies. ...

In TSQL, does the SET command must in it's own batch?

Hi guys, I'm facing a problem now. I use ruby and SQLCMD to generate some TSQL scripts. Now I want to check the syntax of the generated script. I use the following SQL: SET PARSEONLY ON; SELECT 888 SET PARSEONLY OFF; I test it in SSMS, when you select these three statements as a whole batch, sql server will give me the result, which ...

Combine fields in sql server

Hoe to combine rows in sql server 2000 ...

Trigger only modify updated/inserted row

Hi I have the following trigger. ALTER TRIGGER [dbo].[DivisionLastModified] ON [dbo].[tb_Division] WITH EXECUTE AS CALLER FOR INSERT, UPDATE AS BEGIN UPDATE tb_Division SET LastModified = GetDate() END This updates all rows however I only wish to modify the update/added row. Is this achievable? ...

How to concatenate using in sql server

I have a table where the data are like Data a b c I need to write a SQL query to bring the following output Data abc How to do the same by using in SQL Server 2000 Thanks ...

Identity of inserted/updated row in trigger

I have the following trigger but need ti find the identity of the row so I don't update all records in the table. How can I get the identity of the affected row? BEGIN UPDATE tb_Division SET LastModified = GetDate() WHERE "id of inserted/updated row" END ...

Sql server equivalent for this mysql query?

I ve formatted a date column in mysql like DATE_FORMAT(enquiry.enquiryDate,'%d-%b-%Y') as enquiryDate and now i want sql server equivalent for this? ...

How to create maintenance plan in sql server?

when i m trying to create new maintenance plan in sql server it is popping up this error- TITLE: Microsoft SQL Server Management Studio ------------------------------ 'Agent XPs' component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Agent XPs' by using sp_configu...

SQL Server 2005: problem with old SQL Server 2000 database

I attached database from SQL Server 2000 to SQL Server 2005 and it worked well but I had column called (Add Date) which had the Date time of input data and when I insert new data after attached data base to SQL Server 2005 the new data insert with same data 12.00 also it converted all old date to 12.00. Please anyone help me how I can ...

Creating an UPDATE script in SQL Server 2005

I have a table in SQL Server 2005 filled with data. Is there a method by which I can generate update statements including the data in it? ...

SQL query with not exists

Hi, I have this query but for some reason the StartDate values are not getting filtered. What's wrong with it? Please let me know. SELECT * FROM TableA A WHERE NOT EXISTS( SELECT * FROM TableB B WHERE A.pId = B.pId and A.StartDate >= '20-JUN-10' ) ...