sql-server

What should be returned when inserting into SQL?

A few months back, I started using a CRUD script generator for SQL Server. The default insert statement that this generator produces, SELECTs the inserted row at the end of the stored procedure. It does the same for the UPDATE too. The previous way (and the only other way I have seen online) is to just return the newly inserted Id back ...

Change the ANSI_NULLS setting for all Stored Procedures in the Database

We have some problems with the ANSI_NULLS setting and computed columns and we have a ton of stored procedures that have SET ANSI_NULLS OFF We want to change them all to SET ANSI_NULLS ON Is there an easy way to do that or must I extract all the SPs to a script, change it and run it again to drop and recreate all the SPa ...

How do I copy SQL Server 2008 database via C# code

Hi! I want to copy an existing SQL Server 2008 database schema, but not the data, to a new database on the same server (i.e MyDB => MyDB_Test) using C#. I found some sample code at http://www.codeproject.com/KB/cs/CopyDBSchemaUsingSMO.aspx that seems to do exactly what I want but it kept throwing the following error on the ddatabase....

Syntax for INSERTing into a table with no values?

I have a table created with the following schema: CREATE TABLE [dbo].[Visualizations] ( VisualizationID int identity (1,1) NOT NULL ) Since the table has no settable fields, I'm not sure how to insert a record. I tried: INSERT INTO [Visualizations]; INSERT INTO [Visualizations] () VALUES (); Neither work. What is the p...

SQL Server 2005 to SQL Server CE Merge Replication

Hi, In my organization, we have a SQL Server 2005 database server (DBServer). Users of an application will normally be connected to DBServer, but, occasionally, would like to disconnect and continue their work on a laptop using SQL Server Compact Edition 3.5 (SQLCE). Due to this, we have been looking into using Merge Replication betwe...

Oracle 10g timestamp importing into SQL Server as clob

We're importing an Oracle 10g database into SQL Server 2008. When using the 'SQL Server Import and Export Wizard', the Oracle fields with a datatype of 'timestamp(6)' get converted into a 'CLOB' in SQL Server. Why doesn't it get converted into a 'date' datatype? ...

How do I prevent SQL Server from concatenating XML results with the same name

I am trying to generate an XML document using the XML features in SQL 2008 but I'm running into an issue where the document requires two nodes to have the same name but SQL Server automatically concatenates any nodes with the same name. For example: <Location> <Address>Some Street</Address> <Address>Some other info</Address> </Loca...

Encrypt/Decrypt Sql Server 2005 encrypted column in .Net

Hello, I am in need to encrypt/decrypt data that has been encrypted on the database (Sql Server 2005) level in the .Net code. RjindaelManaged with 256 bit key length and 128 bit block size is the equivalent of AES 256 algorithm, but I don't know how to go about matching Key and IV so that both Sql Server and .Net encryption methods woul...

Separating encrypt and decrypt privilidges in SQL Server

Hi there, I am trying to save sensitive information on DB with encryption and all users can put their information in DB after encrypting it, but only privilidged users can decrypt and see it. How can i achieve it using SQL Server 2008 key/certificate/encryption mechanism? Thanks, Ebe. ...

At how many returned records should I begin expecting performance problems?

I have a query that I have been tuning for some time but I can't seem to get the execution time down much. In the execution plan everything looks like it is doing what it is supposed to, no large costs associated with any particular part of the query, everything is using index seek where it is supposed to. When I run the same query aga...

update with inner join, update 2 columns from both tables

this is my query in sql server 2008 - UPDATE a SET a.col2 = 'new', a.col3 = 'www.google.com', b.col1 = '10' FROM table a INNER JOIN table b ON a.col1 = b.col1 WHERE a.col1 = 7 it crashes stating "Invalid column name b.col1." How do i make this work? ...

Count number of entries in whole SQL Server database

Is there any way I can count the number of all entries in a SQL Server database? Preferably with only one query. Edit: The total amount of entries in all tables in a given database. ...

Getting Started with Sync Framework

I'm having some trouble getting started with the Sync Framework. In doing research, it looks like the Sync Framework is a better fit for what we need than replication or a custom-rolled solution. Basically, we need to keep some datasets synced from our central office with every store in the company to overcome shortfalls with crappy DS...

Which SQL operation will give me the product of two tuples?

Refresh my memory. I can't recall how to join tuples (a,b) and (c) to produce (a,b)*(c). For example: n --- 0 1 2 And site_id value ----------- ------------- 1 a 1 b 2 c I'd like to end up with: site_id value n ----------- -------------- -- 1 a 0 1 a...

Setting A Date to End the Use of a Section of a SQL Script

I am using SQL 2005. For one of our customers, we run a script everytime we set-up a new database. The script defines what information remains and what information is deleted from the database....we use a master database to set 'typical' default information. I have been asked to add a delete statement to the script with a 'test' for t...

TSQL to know database role members

Hi, I am using SQL 2000 and SQL 2005. I want to know which logins have db_owner or db_accessadmin rights to which databases. I can click on users or database roles in every database to see that. Could this be done in an easier way using TSQL? Thanks in advance ...

SQL Query ; I want to get Enquiry_No which has not been updated since last 7 days

I am having two tables TblEnquiry with Enquiry _No as Primary Key and tblHistory for maintaing updatiing details with Enquiry_No as foreign key and History_CreatedOn field for date. I want to get Enquiries which have not been updated since last 7 days. ...

Does using WHERE IN hurt query performance?

I've heard that using an IN Clause can hurt performance because it doesn't use Indexes properly. See example below: SELECT ID, Name, Address FROM people WHERE id IN (SELECT ParsedValue FROM UDF_ParseListToTable(@IDList)) Is it better to use the form below to get these results? SELECT ID,Name,Address FROM People as p INNER JOIN UDF_...

stuck while uploading an image file in sql server 2008 from vb.net code

ok so this is the code i used from this site. everything works fine, but i need a little different code to upload image, and i dont know what to do - here's the code - Private Sub btnAttach_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnAttach.Click Dim iLength As Integer = CType(File1.PostedFile.In...

stuck while uploading image file in sql server though vb.net

Reposting the same question because after posting, could not edit the question. please read the bottom especially, if u read this question before - ok so this is the code i used from this site. everything works fine, but i need a little different code to upload image, and i dont know what to do - here's the code - Private Sub btnAttach...