sql-server-2005

Should I use SqlBulkCopy or Stored Procedure to import data

一个人想着一个人 提交于 2019-12-12 02:27:30
问题 I've got a log file which is 248 MB and it can extend up to a GB. So you can imagine how many rows there can be.I need to import all the rows into a table in an SQL Server database. For that I first create a DataTable and add all the lines in the log file into that DataTable as new rows. This happens pretty fast. More than a million records get added to the table in about 30 seconds. After the table is filled with the lines I then import the records in the DataTable to the database using

Can Joins between views and table hurt performance?

两盒软妹~` 提交于 2019-12-12 02:15:16
问题 I am new in sql server, my manager has given me job where i have to find out performance of query in sql server 2008. That query is very complex having joins between views and table. I read in internet that joins between views and table cause performance hurt? If any expert can help me on this? Any good link where i found knowledge of this? How to calculate query performance in sql server? 回答1: Look at the query plan - it could be anything. Missing indexes on one of the underlying view tables

SQL Delete Query

杀马特。学长 韩版系。学妹 提交于 2019-12-12 02:12:32
问题 I need to write an SQL script that selects one record in table1, then does a lookup in the remaining tables in the database. If it doesn't find the record, I need delete the record from table1. Anyone provide some sample script? 回答1: One example delete table1 where not exists (select 1 from Table2 where table1.SomeColumn = Table2.SomeColumn) AND table1.SomeColumn = 5 --just an example, Leave the AND out if you want to delete all the rows from table 1 that do not exist in table 2 you can also

How to apply Update if an item exists and Insert otherwise

ぐ巨炮叔叔 提交于 2019-12-12 02:09:35
问题 How to create a procedure that goes from the top of the table and compares the value to null - If a match is found, insert an element in this position. - If not, the element is inserted into a new row I need to correct a second row which contains null values in 4 last columns regardless of values in the Id and PropertyId columns Here is a screenshot of my DB Here is a samples of data: Now it works so, which is not suitable to me, instead it should update the row with null values like on the

Database Connection Problem with MS SQL Database: JDBC-ODBC Driver from JSP

时间秒杀一切 提交于 2019-12-12 01:57:29
问题 I'm using Netbeans 6.8 to develop application using JSP. I'm able to work with it properly in my project guides system. But i'm unable to get the connection to database from my system. It shows error unable to connect . I have not changed any of the codes. How can I fix this error? 回答1: This can have one or more of the following causes: IP address or hostname in JDBC URL is wrong. Hostname in JDBC URL is not recognized by local DNS server. Port number is missing or wrong in JDBC URL. DB

Eliminate row that has null value using CTE

守給你的承諾、 提交于 2019-12-12 01:54:02
问题 I have some data as RowIdentifier ID RowID Position Data Rn 1 1 1 a1 A1 1 2 1 2 a2 A2 1 3 1 3 a3 NULL 1 4 1 4 a3 A3 2 5 1 1 b1 B1 1 6 1 2 b2 NULL 1 7 1 3 b2 B2 2 8 1 4 b3 B3 1 The desired output being ID RowID Position Data 1 1 a1 A1 1 1 b1 B1 1 2 a2 A2 1 2 b2 B2 1 3 a3 A3 1 3 b3 B3 I need to eliminate those rows where the Positions are duplicate and whose data are null. i.e. in the example, in RowIdentifier 3 and 4, the value in Position column is a3 but the thired RowIdentifier record will

how to copy top 1000 records from 7000 records in existing table to other new table

亡梦爱人 提交于 2019-12-12 01:42:16
问题 I have a table A which consists more than 7k records,Now i am creating a new table B .In my new table B I need to copy only 1000 records from table A which has more than 7000 records. No condition applies, it may be any thousand records from 7000 . 回答1: In SQL Server SELECT top 1000 * INTO newTableName FROM oldTableName; In MySQL SELECT * INTO newTableName FROM oldTableName Limit 1000; 回答2: INSERT INTO TABLEB(Col1, Col2, .... colN) SELECT TOP 1000 Col1, Col2, .... colN FROM TABLEA 回答3: You

How can i use substring in SQL? [duplicate]

六眼飞鱼酱① 提交于 2019-12-12 01:35:15
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: How can I rearrange string with SQL? Declare @CustTotalCount as int Declare @CustMatchCount as int select @CustTotalCount = count(*) from ENG_CUSTOMERTALLY select @CustMatchCount = count(*) from Task where MPDReference in( select ENG_CUSTOMERTALLY_CUSTOMERTASKNUMBER from dbo.ENG_CUSTOMERTALLY) if(@CustTotalCount>@CustMatchCount) select distinct substring(ENG_CUSTOMERMYCROSS_MYTECHNIC_TASK_NO, charindex('-', ENG

Recursively grab all data based on a parent id

℡╲_俬逩灬. 提交于 2019-12-12 01:35:14
问题 We have a table where rows recursively link to another row. I want to pull data associated with a given parentId and all it's children. Where parentId is one from the root row. I thought I have seen or done something like that before, but I am unable to find it now. Can this be done in SQL or is it better to do this in code? I want the list to look like this when I'm done: Parent Child Grandchild 回答1: This can be done in SQL Server 2005 and above using Common Table Expressions (CTEs). Here is

.NET TransactionScopes and SQL 2005 Lightweight Transaction Manager - Multiple Connections same SPID?

泄露秘密 提交于 2019-12-12 01:35:00
问题 Can someone shed light on what is happening behind the scenes with the SQL Lightweight transaction manager when multiple connections are opened to the same DB, using the Microsoft Data Access Application Block (DAAB)? With the below code, we verified that MSDTC is indeed not required when opening 'multiple connections' to the same database. This was the first scenario I tested: (where Txn1 and Txn2 use EntLib 4.1 to open a connection to the same DB and call different SPROCS) using (var ts =