sql-server

autosizing sql server database diagram view

i see there is "arrange tables" that organizes your table relationships to be clear. is there anyway to autosize the tables so it shows: the full name of the table the full height to show all fields. i find myself tweaking tables over and over manually and its a pain. I would hope there would be some way to auto correct the sizing ...

how can I generate sql file contain insert statement and data programatically or manually?

Hi every one . I'm work on project in c# ,and I want to generate data from my db and pass it to the server just when I need to do that, so I can then run this file on server , Can I generate this file from c#? and how can I generate file like this from sql: SET NOCOUNT ON GO USE master GO IF EXISTS ( SELECT * FROM sys...

How to handle ascii control characters in sql server?

How can we handle ascii characters using sql server 2005? Which data type can I use to store ascii characters, mainly control characters? For example: I have a file with strings delimited by some control characters like backspace. I need to read this file into my sql server tables. I want to know what data type (char,nchar,varchar, .....

SQL CASE [Column] WHEN IN ('case1', 'case2') THEN 'oops' END?

Is there a way to check a CASE when it's in an array: SELECT CASE [Option] WHEN IN (1, 3, 99) THEN 'Wrong option' ELSE 'You go!' END ...

Removing duplicates in SQL Server - Unusual Scenario

Hi Guys, The database I'm currently working on is for a scientific instrument that records data at certain points in time. My instrument records per second, but with a resolution of 5 seconds. ID Total Particles DateandTime 38313 602 2009-01-27 16:25:48.000 38314 602 2009-01-27 16:25:49.000 38315 ...

How to collate SQL_Latin1_General_CP1_CI_AS using IN operator

I want to filter records on 'Email' my query is like this. SELECT * FROM #temp WHERE email NOT IN (SELECT email FROM Customer) It gives me following error Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation. I can use collate if there is equal op...

How to resolve Sql Server Error Message 117 - Too many prefixes for object name?

I am transferring a database from one hosting provider to another. The current provider uses the domain name as part of the user name. The domain name is a .co.nz domain. So some objects in the database have a fully qualified name of [email protected]. Im trying to alter the schema of these objects to put them into a dbo sche...

Drop multiple tables with string

I have tables like lg-010-a..., lg-010-ac..., and so on, I have abc database, I have a command window: drop table from abc where Table_Name like 'lg-010-%' Will this drop all the tables starting with lg-010-? ...

How to alter SQL in "Edit Top 200 Rows" in SSMS 2008

In SQL Server 2008 Management Studio, when I right click on a database table and choose "Select Top 100 Rows", I can then e.g. easily add a "ORDER BY " statement to the SQL. That works fine. But when I do choose "Edit Top 200 Rows", I don't have the ability to alter the SQL (which makes it hard to find and edit a record just added in th...

Sql Server OLEDB provider error. The provider ran out of memory error.

Sorry for my english :). I have a windows service. Service report some excel files weekly. But ı got a"OLE DB provider 'SQLOLEDB' reported an error. The provider ran out of memory" Ole Db error. Service use SQl Server 8.00.194 and it link another SQL Server. I do not know why ı receive this error. Thanks for help. ...

An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON SQL Server

I'm trying to do this query INSERT INTO dbo.tbl_A_archive SELECT * FROM SERVER0031.DB.dbo.tbl_A but am getting the following error message even after i do set identity_insert dbo.tbl_A_archive on An explicit value for the identity column in table 'dbo.tbl_A_archive' can only be specified when a column list is used and I...

Table Structure for Multiple Histrory

i want to create table to keep histroy of the ammendments & history of the object. for That i have created two column Primary Key ( Id & update date) I have 3 more date columns to maintain history & Status Column for Actual object history. Status , StatusFrom , Statusto, UpdateDate & NextUpdateDate UpdateDate & NextUpdateDate is for ma...

sql server: Estimated number of rows is way off

I get a bizarre execution plan behavior from SQL Server (2005). Table: TableName: LOG ID int, Name varchar(50) (Table contains around 1000 rows) Query: Select * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY ID DESC) as Row, ID, Name FROM Log ) as LogWithRowNumbers WHERE Row>=1 and Row<=2 It estimates the number of rows returned a...

How can I execute a SP and depending on it's result execute another query which if fails should revert back what the SP has done?

I think it's a basic SQL question...sorry..new to it... :-) I want to execute a SP inside which { I want to execute a SP (using EXEC) and depending on it's result I want to execute another query (INSERT) which if fails for any reason should revert back what the SP has done? } How can I do this? Transactions? If yes, how? PLEASE...

SQL/Oracle Server, Full Outer Join and 3 or more Tables

I got a little problem. I'm using Full outer Join in Sql server - so far it works but now I add a table and it doesn't work as it should. Here is my code: SELECT * FROM Table1 h , (db1..Table2 s FULL OUTER JOIN db1..Table3 k on k.attributT3_1 = s.attributT2_1 and left(k.attributT3_2,4) = year(s.attributT2_2) and substring(k....

Using NHibernate transaction in SqlBulkCopy

I'm storing some data using NHibernate, and I need to insert huge amount of data as a part of this action - i.e. in the same transaction. Code looks like this: using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.SaveOrUpdate(something); // ... Sq...

Unable to do LIKE search on word containing "aa"

Hi I have a field with the following content in a record in my SQL Server database: salsaaften It means "salsa evening" in danish for those interested :) When I do like this I am not able to find the record: SELECT * FROM table_name WHERE field_name LIKE '%salsa%' However, when I do this, I find the record perfectly fi...

SQL Pivot question

I'm having a hard time getting my head around a query im trying to build with SQL Server 2005. I have a table, lets call its sales: SaleId (int) (pk) EmployeeId (int) SaleDate(datetime) I want to produce a report listing the total number of sales by an employee for each day in a given data range. So, for example I want the see all sa...

return distinct products based on product_id

Right now the query below is retrieving more then one product record. How can I limit the results set to only retrieving the one record per product_ID? Multiple records will be returned from different products, but I only need one product line per product_id. This is MS SQL 2005 SELECT DISTINCT dbo.Products.Product_ID AS Expr1, ...

What database user permissions are needed?

FYI: SQL Server 2005 I have a database user account (user_web) that has the ability to connect to and run queries and stored procedures in my database. Specifically, I have given the user the db_datareader and db_datawriter roles as well as granted them execute permission on the specific stored procedures it needs to be able to run. In...