sql-server

Get Id after an INSERT in SQL Server in a multithread enviromment ?

How can I get id after an INSERT in SQL Server ? For my insert, I use context.ExecuteStoreCommand() Warning: I have a multi-threaded application which inserts "at the same time" some data in the same table. ...

Unable to create new Team project over the internet getting SQl Reporting service resolve error

Hi I have installed a Team Foundation Server 2010, and it works perfectly over my Lan, but I need it to work over the internet too. My problem is that when Im connected to my team server over the internet, I get the following error, when I try to create a new Team project. TF218027: The following reporting folder could not be created o...

"Warn on null primary keys" table design option in SSMS

I SSMS (2008R2) menu Tools --> Options --> Designers --> Table and Database Designers --> "Warn on null primary keys" I played checking and unchecking this checkbox but could not detect the differences. What is it for? My related questions, probably: NULL permitted in Primary Key - why and in which DBMS? Why to use “not null pr...

SQL - Server - What is sp_addextendedproperty commonly used for, and is it likely this code (see) is auto generated?

Hi, Just after a quick answer here. I've come across this view in a database I'm working on. It has a large code section beneath it which uses sp_addextendedproperties. This code looks like it was generated by a tool to me (preview below) - can any one tell me which tool it likely came from and what the point of it is (Just some of the...

how to debug a long script in management studio?

I have a very long T-sql script, it is a single batch, something like DECLARE variables select into temptable... cursor... insert... update.. as I run the script I have (1 row(s) affected) (5 row(s) affected) [...] ERROR (2 row(s) affected) etc... I would like to run step by step the script to identify which is the command...

Database Performance Solution - "View Caching" - Is this a good idea?

Hi, A little context first: I would say I have good SQL server experience, but am a developer, not a DBA. My current task is to improve on the performance of a database, which has been built with a very heavy reliance on views. The application is peppered with inline sql, and using Tuning Advisor only suggests a couple of missing index...

What is ADO.NET?

What is ADO.NET and what difference between it and SQL Server? ...

SCOPE_IDENTITY in C# - range

Hello, I've checked the documentation for SCOPE_IDENTITY(), and it says "A scope is a module: a stored procedure, trigger, function, or batch." That is simple when I'm running a query in SSMSE, but in C# I'm using SqlCommand for executing my statements. The question is: what is the scope there? Is executing subsequent commands under on...

SqlBulkCopy from a List<>

How can I make a big insertion with SqlBulkCopy from a List<> of simple object ? Does I to implement my custom IDataReader ? ...

SQL Insertion without duplication

Is there a specific command in C# for SQL Server in order to INSERT a lot of rows with the condition : if a row already exists in database doens't duplicate it during insertion ? Edited In a sqlbulkcopy, I'd like to avoid exception because a row is already in the table ? ...

Get all table names of a particular database by SQL query?

I working on application which can deal with multiple database servers like "MySQL" and "MS SQL Server". I want to get tables names of a particular database using a general query which should suitable for all database types. I have tried following: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' But it ...

C# code and SQL Server performance

I have a SQL Server database designed like this : TableParameter Id (int, PRIMARY KEY, IDENTITY) Name1 (string) Name2 (string, can be null) Name3 (string, can be null) Name4 (string, can be null) TableValue Iteration (int) IdTableParameter (int, FOREIGN KEY) Type (string) Value (de...

SQL server transaction

I need to understand about sql server transaction? I have gone through some articles available on google but I have not understood anything. Can anyone help me? ...

sql Database Restore

Hi I want restore database from backup file so i have used the following command restore database myTestDbName from disk ='C:\temp\mybackuo.bak' while executing the command I got following error "The tail of the log for the database "myTestDbName" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains...

Checking if MSSQL database is running in MULTI_USER mode

How can I check what mode a particular database is in? ...

extension=php_mssql.dll - error load

hi, I am configuring a server IIS7 to work with php and mssql in php.ini and when I try to call the "extension = php_mssql.dll" appears to me an error when I refresh the site. "500 - Internal server error. There is a problem with the resource you are looking for, and it can not be displayed. " Thanks ...

selecting top( x ) multiple times

Sorry for the rubbish title but hopefully this will explain: Given the table name | data --------------------- 1 | 1000 1 | 2000 1 | 3000 2 | 1500 2 | 2500 2 | 3500 I want to be able to select the top( x ) for all names ordered by the data value. So if x = 2 the retur...

Suitable indexes for sorting in ranking functions

I have a table which keeps parent-child-relations between items. Those can be changed over time, and it is necessary to keep a complete history so that I can query how the relations were at any time. The table is something like this (I removed some columns and the primary key etc. to reduce noise): CREATE TABLE [tblRelation]( [dtCr...

Howto query average of most recent data in sqlserver

I want to find the average of the most recent x results. Is it possible to use an aggregate function on a limited number of results with sql server? Here is what I have tried and the errors I get: select avg(top(100) convert(float, AnalysisData)) from tab order by DatePerformed desc Msg 156, Level 15, State 1, Line 1 Incorrect s...

How can I model non-matching Foreign Keys

I'm trying to use EF to model an existing SQL database. The DB is multi-tenant by having a clientID column in every single table (I cannot change this). I have table structure like the following. Table 'ItemID' columns: ClientID (pk) ItemID (pk) ItemName Table 'Items' columns: ClientID (PK) ItemID (PK) [FK to ItemID.ItemID] Versi...