sql-server

MS Access: Permission problems with views

"I'll use an Access ADP" I said, "it's only a tiny project and I've got better things to do", I said, "I can build an interface really quickly in Access" I said. </sarcasm> Sorry for the rant, but it's Friday, I have a date in just under two hours, and I'm here late because this just isn't working - so, in despair, I turn to SO for hel...

Xchange column values in table in SQL Server

Hello people. I have problem to solve: Suppose in database is table TAB1(id,numb,text). The task is to exchange two column values in column 'numb' on some query in column 'text'. For example: We have ID | NUMB | TEXT 1 | 22 | hello <- this record 2 | 25 | today 3 | 34 | wow <- this record 4 | 53 | what...

Primary Key Names in Fluent Nhibernate

Is there a way in fluent nhibernate (or possibly NHibernate in general) to tell it to generate the primary keys differently? It creates the column name for the key fine, but the index/constraint gets weird generated names like: PK_Address_3214EC2725332734 PK_CreditCa_3214EC2756CA82C8 etc... I can use straight sql to rename them but ...

SQL Full-Text Indexing Issue

UPDATE: I have figured out a way using a form of dynamic sql to fix this problem, thanks anyway for any help. Hi, there is something that I need to accomplish with the use of Full-Text Indexing. This is it: The fact of the matter is when I run a query (with a stored procedure) that looks like (with a parameter (@name) that was obvious...

SQL Server 2000 - Filter by String Length

Hello, I have a database on a SQL Server 2000 server. This database has a table called "Person" that has a field call "FullName" that is a VARCHAR(100). I am trying to write a query that will allow me to get all records that have a name. Records that do not have a name have a FullName value of either null or an empty string. How do I g...

What can I do about a SQL Server ghost FK constraint?

I'm having some trouble with a SQL Server 2005 database that seems like it's keeping a ghost constraint around. I've got a script that drops the constraint in question, does some work, and then re-adds the same constraint. Normally, it works fine. Now, however, it can't re-add the constraint because the database says that it already exis...

Question About DateCreated and DateModified Columns - SQL Server

CREATE TABLE Customer ( customerID int identity (500,20) CONSTRAINT . . dateCreated datetime DEFAULT GetDate() NOT NULL, dateModified datetime DEFAULT GetDate() NOT NULL ); When i insert a record, dateCreated and dateModified gets set to default date/time. When i update/modify the r...

How to drop all stored procedures at once in SQL Server database?

Currently we use separate a drop statements for each stored procedure in the script file: IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MySP]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[MySP] Is there a way to drop them all at once, or maybe in a loop? ...

Long time to load first sql connection in .NET

For some reason it takes 7 seconds to open a connection to a sql server database for the firt time, subsequent connections takes a second. any idea what could be the reason? I'm using C# and asp.net Its after compilation, i essence every time i restart the site, which means every time it needs to actualy create the "first" connection....

MS Query Analyzer / Management Studio replacement?

I've been using SQL Server since version 6.5 and I've always been a bit amazed at the fact that the tools seem to be targeted to DBAs rather than developers. I liked the simplicity and speed of the Query Analyzer for example, but hated the built-in editor, which was really no better than a syntax coloring-capable Notepad. Now that we hav...

how do I subtract values from two select statements

I would like to subtract one value from another value. The schema of the table is as follows: tag, datetime,value ------------ tag1, 2010-1-1 10:10:00, 123 tag2, 2010-2-2 10:12:00. 321 select * from ( (Select Max(Value) as [Value1] from History WHERE Datetime ='2010-1-1 10:10' and tagname ='tag1') as v1 -...

adding users, membership, and roles to site

I have followed scott's gu tutorial here I uploaded the whole database to my site. Before doing what Scott's says I had one username stored in the membership. How can I create an additional user now that the table is in the web host? I can see that there's aspnet_Membership, aspnet_Applications, etc..etc ...

Distinct with Count and SQl Server 2005

Hey everyone, Trying to work on a query that will return the top 3 selling products with the three having a distinct artist. Im getting stuck on getting the unique artist. Simplified Table schema Product ProductID Product Name Artist Name OrderItem ProductID Qty So results would look like this... PID artist ...

Calling stored procedure from another stored procedure and returning result as new columns

How to call stored procedure from another stored procedure and return the result as first one's column? ALTER PROCEDURE [dbo].[GetItems] AS SET NOCOUNT ON SELECT ID, AddedDate, Title,Description, Result of Stored Procedure "CountAll" call with parameter ID as Total FROM dbo.Table1 And also: how to be if CountAll stored proced...

What is the problem with the logic in my UPDATE statement?

Hello, I would appreciate some help with an UPDATE statement. I want to update tblOrderHead with the content from tblCustomer where the intDocumentNo corresponds to the parameter @intDocumentNo. But when I run the my statement, the order table is only updated with the content from the first row of the customer table. What is the probl...

ALTER TABLE my_table ADD @column INT

If i want to use a variable as name of the new column, is this posible in MS SQL? Example that dont work: ALTER TABLE my_table ADD @column INT This worked great for me: EXEC ('ALTER TABLE my_table ADD ' + @column + ' INT') ...

How to backup database (SQL Server 2008) in C# without using SMO?

I have this code and it is not working but I don't why? try { saveFileDialog1.Filter = "SQL Server database backup files|*.bak"; saveFileDialog1.Title = "Database Backup"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { SqlCommand bu2 = new SqlCommand(); SqlConnection s = new SqlConnection("Data Source=M1...

Is SQL server the best DB for Storing and comparing images in database for a small ecommerce application.

I have been trying to create a small e-commerce web based application using MS Dot Net framework. The application will let the user allow to store the image of their product that they want to sell or purchase, then they will have the option to upload the image of a particular product and compare that image with the similar images in the ...

Generating the SQL query plan takes 5 minutes, the query itself runs in milliseconds. What's up?

I have a fairly complex (or ugly depending on how you look at it) stored procedure running on SQL Server 2008. It bases a lot of the logic on a view that has a pk table and a fk table. The fk table is left joined to the pk table slightly more than 30 times (the fk table has a poor design - it uses name value pairs that I need to flatte...

sql server 2005 indexes and low cardinality

How does SQL Server determine whether a table column has low cardinality? The reason I ask is because query optimizer would most probably not use an index on a gender column (values 'm' and 'f'). However how would it determine the cardinality of the gender column to come to that decision? On top of this, if in the unlikely event that I...