sql-server

Can you lazy load when model has associations, but the database does not?

Hi, I am working on an old database, that i do not want to touch or modify in any way if possible. I want to build a new application that uses it's data but the database has no actual relations despite having primary and foreign keys linking tables. If i import these tables into an Entity Framework model and add the associations manual...

Extracting nth word onwards

hi, how do i extract words from the nth word onwards in sql server? eg. | Description | | This is a nice dress | extracting the 4th word onwards, would output 'nice dress' ...

SQL Server 2008 : replace string

I have a table with an erroneous symbol('�') in a number of rows in one column. The TSQL script below does not work. UPDATE S SET S.Offering_Details = REPLACE(S.Offering_Details, '�', '...') FROM tblSacrifices S The column in question has datatype of nvarchar(230) and allows null entries. The data came from a csv file converted from...

SQL Server SMO take back up locally from remote server

My question is straight forward, how can I program SQL SMO to take local backup, by connecting to a remote server. I want to save the bak file to a local machine which is connecting to the remote server. Also I want users with only certain privilege to be able to save backups locally. ...

SQL-Server Free Text Search - NEAR operator

This may sound a dumb question, can someone confirm that within a Free Text search that the query Word1 NEAR Word2 IS identical to Word2 NEAR Word1 ?? So that Word order is not relevant. I am trying to hit highlight the results and if this is the case I need to look for occurrences of the reversal of the original search term words. ...

How do I insert unicode into MS-SQL ?

I want to insert info.NativeName into a nvarchar field in the database. It doesn't work, all I get is ??????? where the encoding is not western/latin. Outputting listcultures directly in an asp.net website on page_onload worked fine, but it seems not to work via database. Public Sub listcultures() 'Dim x As System.DateTime = DateTi...

How to select even non existent values

I'm using SQL-Server 2005 I have two tables, Users and Orders. Each user can have many orders. Tables connected via userID. Orders has date column ( which is when order was made ). Users have registrationSite column ( which is who is the affiliate site behind user and all of his orders ). I want to select sum of orders per day and site...

SQL Server 2008 Table Partitioning

I have a huge database that has several tables that hold several million records. It's holding engineering data for a client and continually grows. This is impacting performance, even with optimised indexing. So I've been looking at partitioning. However, I would be looking at partitioning on a version held in a table. In it's most sim...

Is there any security benefit in using a stored procedure to toggle a boolean value from a checkbox

I have a boolean variable value stored in an SQL Server database. This is presented to end users as a checkbox on an ASP.NET webpage. Toggling the checkbox naturally updates the value in the database. I was about to remove the SQL query that is written in plain text in the C# code behind and replace it with a stored procedure in order t...

Return NEWSEQUENTIALID() as an output parameter

Imagine a table that looks like this: CREATE TABLE [dbo].[test]( [id] [uniqueidentifier] NULL, [name] [varchar](50) NULL ) GO ALTER TABLE [dbo].[test] ADD CONSTRAINT [DF_test_id] DEFAULT (newsequentialid()) FOR [id] GO With an INSERT stored procedure that looks like this: CREATE PROCEDURE [Insert_test] @name as varc...

Is it possible to get a list of relevant words from a full-text index given a specific row?

I wuld like to do som automatic tagging of incoming text in our system and I was wondering if a full-text index is capable of providing a a ranked list of words given an indexed row. If not, do you have any suggestions on how to do this? We already have a system in place for auto tagging but its fairly brute-force (aka. slow) in its met...

Does something like Common Table Expressions exist in PL/SQL?

I recently learned about CTE's in SQL Server and am attempting to use it in PL/SQL. I do not need the recurive benefits of it, however, I would like to use it in lieu of creating a view and to improve query performance. Just looking for some direction on what code may be similar. ...

how to Create SQL Server Database with User?

How (in SQL Server) to create a database and create a user and this user will be an admin on this database only with SQL script? I mean this user can not do/access any thing out side this database! and is it possible to create user that has only can add, update/edit or delete data from tables and nothing else? I know how to do that in ...

Performance characteristics of T-SQL CTEs

Hi guys, I've got some SQL that looks roughly like this: with InterestingObjects(ObjectID, OtherInformation, Whatever) as ( select X.ObjectID, Y.OtherInformation, Z.Whatever from X join Y join Z -- abbreviated for brevity ) -- ...long query follows, which uses InterestingObjects in several more CTEs, -- and then uses those CTE...

2-column distinct?

I'm trying to select two distinct numbers id1 and id2 from the following table: tb_table1( bigint id1 bigint id2 bigint userid) if I do select distinct id1, id2 from tb_table1 I'll get, for example, two rows, (111, 222) and (222,111). I only want one of those rows since I don't care which column, id1, or id2 that the result ge...

using inserted and deleted tables in the triggers

I want to write triggers to work with the inserted and deleted tables. I have written the trigger for inserting : CREATE TRIGGER FILL_TABLE ON Person FOR INSERT AS DECLARE @ID int SELECT @ID = p.ID FROM Person AS p INNER JOIN inserted AS i ON p.ID = i.ID DECLARE @uName char(30); SELECT @uName=SYSTEM_USER INSERT tblOperation...

SQL Server - table seems to be blocked

Using NHibernate, I have just attempted to save a graph of objects using NHibernate. The save failed due to a not-null constraint violation. I am now finding that a table in the database corresponding to one of the objects in the graph now appears to be locked. I cannot query it. Whenever I try, it just sits there doing nothing until I ...

Creating a unique id (pin number) for each record of a table

I want to create a pin number that is unique within a table but not incremental to make it harder for people to guess. Ideally I'd like to be able to create this within SQL Server but I can do it via ASP.Net if needed. Thanks, Josh EDIT Sorry if I wasn't clear - I'm not looking for a GUID as all I need is a unique id for that table - ...

Reduce SQL Server table fragmentation without adding/dropping a clustered index?

I have a large database (90GB data, 70GB indexes) that's been slowly growing for the past year, and the growth/changes has caused a large amount of internal fragmentation not only of the indexes, but of the tables themselves. It's easy to resolve the (large number of) very fragmented indexes - a REORGANIZE or REBUILD will take care of t...

UTF8 problem sql server

I have some utf8 data which I would like to bulk insert (sql server 2005). I am using the CODEPAGE 65001: BULK INSERT #bla FROM 'D:\bla.txt' WITH ( CODEPAGE=65001, FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n' ) Unfortunatly strings like this: Erdağı end up being stored like this: Erda?? Do I use the wrong code pag...