sql-server

How can I decode SQL Server traffic with wireshark?

I can capture the packets using wireshark, but I can't decode the stream into anything intelligible. This bug suggests that maybe this isn't possible in SQL Server 2005 or newer... https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=3098, but several people on Stack Overflow claimed this was a good method in answers to this question: h...

Updating table with random data With NEWID() does not work

SQL SERVER 2000: I have a table with test data (about 100000 rows), I want to update a column value from another table with some random data from another table. According to this question, This is what I am trying: UPDATE testdata SET type = (SELECT TOP 1 id FROM testtypes ORDER BY CHECKSUM(NEWID())) -- or even UPDATE testdata SET typ...

Defending against a 'WAITFOR DELAY' sql injection attack?

Hi all, The problem We need to defend against a 'WAITFOR DELAY' sql injection attack in our java application. Background [This is long. Skip to 'Solution?' section below if you're in a rush ] Our application mostly uses prepared statements and callable statements (stored procedures) in accessing the database. In a few places we dy...

Recursive t-sql query

Hi I have a table as shown below. ID ParentID Node Name Node Type ------------------------------------------------------------------ 525 524 Root Area Level 1 526 525 C Area Level 2 527 525 A Area Level 2 528 525 D Area Level 2 671 525 E Area Level 2 660 527 B Area Level 3 672 671 F Area Level 3 How can i write ...

Modeling Existential Facts in a Relational Database

I need a way to represent existential relations in a database. For instance I have a bio-historical table (i.e. a family tree) that stores a parent id and a child id which are foreign keys to a people table. This table is used to describe arbitrary family relationships. Thus I’d like to be able to say that X and Y are siblings without ha...

How to Manage User Modifiable Lookup Tables

There is a table in our database that acts very much like a standard lookup table (ID, Description). However, this particular one is not static, the client wants the ability to add entries on the fly. Some entries that will come pre-populated are "special" in that there will be code that checks for them (various business rules). Norma...

SQL Service Broker Success?

I am contemplating converting our internal application from MSMQ and WCF to SSB. We would like a more feature rich system with regards to our queuing. However, I am not seeing a lot of implementations or general information if SSB is in use with .Net. The SSB blog is not very active and I see few posts in general on implementation s...

VB or C# for SQL Server - Just learning SQL Server (going from Access)

I am just getting into SQL Server, and I have some experience with MS Access an Visual Basic (well VB within Access anyway). So I am trying to acquire materials (books, etc) to learn how to program sql server, and I am wondering if I should go the C# route instead of visual basic for sql server?? not super familiar with c# (though i am ...

LEN function not including trailing spaces in SQL Server

I have the following test table in SQL Server 2005: CREATE TABLE [dbo].[TestTable] ( [ID] [int] NOT NULL, [TestField] [varchar](100) NOT NULL ) Populated with: INSERT INTO TestTable (ID, TestField) VALUES (1, 'A value'); -- Len = 7 INSERT INTO TestTable (ID, TestField) VALUES (2, 'Another value '); -- Len = 13 + 6 spaces ...

SQL Server RowVersion

Hey guys, Quick question Re: Implementation of RowVersion. I am looking to include it in my next database (Designing it now) and I am pondering 2 different ways: RowVersion row in all tables A separate RowVersion table which has the ID of the table as a foreign key and linked to it. Anyone tried this? If so what pitfalls or pro's d...

Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET

How can I get the second column with the same column name using OPENXML in MSSQL 2005? Here is the result set that I plan to get. columnData1 columnData2 A B C D E F DECLARE @hDoc int, @xmldata varchar(max) SELECT @xmldata = '<?xml version="1.0" encoding="utf-8" ?> <reportResponse> <reportDataRow rowNum="1"> <columnData colNum...

please tell me how to create update query for such a problem

i have two tables: 1. CREATE TABLE [dbo].[HotelSourceMap]( [hotelsourcemapid] [bigint] IDENTITY(1,1) NOT NULL, [dspartnerid] [bigint] NOT NULL, [dshotelid] [bigint] NOT NULL, [countrycode] [varchar](5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [countryid] [bigint] NULL) 2. CREATE TABLE [dbo].[country]( [countryId] [smallint] IDENTIT...

SQL Server: Group results on time interval

Hey guys, I've got an MS SQL Server table that records our plant's alarm events with a row for each alarm and a datetime column to capture when the alarm happened. We run our plant in 12 hour shifts (6 am to 6pm, 6pm to 6am) and I need to figure out how many alarms we're getting each shift. How do I group my results to get that? The...

Organising Dbs and tables in SSMS

This is a repost of a question I asked 4 or 5 days ago, with zero response. Hoping for more luck this time... (Using SQL Server 2008) Hi Within the next few weeks I plan to introduce SQL server to an office that is in dire need of a proper data server. Currently there is a heavy reliance on loose Excel and Access file (supplemented wi...

please tell me what is error in this update query

UPDATE HotelSourceMap SET hsm.hotelid = co.hotelid FROM HotelSourceMap AS hsm JOIN hotels AS co ON (hsm.hotelname= co.[name] AND hsm.cityid = co.cityid) its giving me error: The multi-part identifier "hsm.hotelid" could not be bound. ...

How to connect to SQL Server 2005 database through Ruby

How to connect to SQL Server 2005 database through Ruby in Windows ...

Matching similar city names in SQL

I have a table "City" which contains city names, and I have a another table which I just created and contains cities from different sources. When I run a query to match the cities between the two tables I find about 5000 mismatches. So please give some queries which I can use to match cities (because sometimes users enter city names wi...

how to run a parallel query on sql server 2008?

i want to run a query on multiple processors. what is the syntax to run a parallel query? please provide a sample query ...

NHibernate identifier altered exception

Hi, I am trying to import some large files using batch queries and paralel processing and I'm constantly getting errors like NHibernate.HibernateException: identifier of an instance of xxx was altered from ... to ... I know I am not modifying my primary key at all. I am using NH 2.1.x GA, ThreadStaticSessionContext, every file is proc...

set CONTEXT_INFO select context_info(), locking

Imagine a Table T that is used as follows: At time T0: SPID 1: begin transaction ... insert into T(...) values(...); ... commit; At time T1 SPID 2: begin transaction select * from T where C=cval; ... commit; Assume transaction isolation level set to serializable. Also Assume that SPID1 manages to take TABLOCKX on T ...