sql-server-2008-r2

Reset autoincrement in Microsoft SQL Server 2008 R2

谁说胖子不能爱 提交于 2019-11-29 22:55:43
I created a primary key to be autoincrement. I added two rows: ID=1, ID=2 I deleted these two rows. I added a new row, but the new row's ID was: ID=3 How can I reset or restart the autoincrement to 1? If you use the DBCC CHECKIDENT command: DBCC CHECKIDENT ("YourTableNameHere", RESEED, 1); But use with CAUTION! - this will just reset the IDENTITY to 1 - so your next inserts will get values 1, then 2, and then 3 --> and you'll have a clash with your pre-existing value of 3 here! IDENTITY just dishes out numbers in consecutive order - it does NOT in any way make sure there are no conflicts! If

Remote Procedure call failed with sql server 2008 R2

这一生的挚爱 提交于 2019-11-29 20:50:20
I am working with SQL Server 2008 R2. I am unable to connect to my database remotely. I got the following error. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) I have checked the SQL Server properties and I enable the Allow remote connections . I have checked the Service manager and SQL Server service are

Getting error while running 50 MB script on SQL Server 2008 R2

Deadly 提交于 2019-11-29 20:25:28
I am using SQL Server 2008 R2, I have a script to update the DB, that script is approx 50 MB in size and contains some about 800,000 lines. Error: TITLE: Microsoft SQL Server Management Studio Cannot execute script. ADDITIONAL INFORMATION: Insufficient memory to continue the execution of the program. (mscorlib) Can somebody please help me to run this script without getting this error? use the command-line tool SQLCMD which is much leaner on memory. It is as simple as: SQLCMD -d <database-name> -i filename.sql You need valid credentials to access your SQL Server instance or even to access a

T-SQL Is a sub query for an Update restriction Atomic with the update?

∥☆過路亽.° 提交于 2019-11-29 20:02:51
问题 I've got a simple queue implementation in MS Sql Server 2008 R2. Here's the essense of the queue: CREATE TABLE ToBeProcessed ( Id BIGINT IDENTITY(1,1) PRIMARY KEY NOT NULL, [Priority] INT DEFAULT(100) NOT NULL, IsBeingProcessed BIT default (0) NOT NULL, SomeData nvarchar(MAX) NOT null ) I want to atomically select the top n rows ordered by the priority and the id where IsBeingProcessed is false and update those rows to say they are being processed. I thought I'd use a combination of Update,

Split multiple string's into multiple columns

断了今生、忘了曾经 提交于 2019-11-29 18:21:50
I have the following three different strings which needs to split into three different columns. Example : String 1: Declare @str1 varchar(max) = 'A1,A2,A3' String 2: Declare @str2 varchar(max) = 'B1,B2,B3' String 3: Declare @str2 varchar(max) = 'C1,C2,C3' Note I want to store the above three strings into three different columns. Expected Output : colA colB colC ------------------ A1 B1 C1 A2 B2 C2 A3 B3 C3 Attempt: SQL Fiddle : http://sqlfiddle.com/#!3/d41d8/41345 I know its a bit heavy but it will work Declare @str1 varchar(max) = 'A1,A2,A3' Declare @str2 varchar(max) = 'B1,B2,B3' Declare

How do I find the current version of a SQL Server data-tier application?

大兔子大兔子 提交于 2019-11-29 17:59:13
问题 We are using a SQL Server Data-tier application (dacpac or DAC pack) and I'm having a hard time finding the current version of the database. Is there a way to obtain the current version using any of these methods: From within SQL Server Management Studio Via a SQL statement Programmatically using .NET code 回答1: From within SQL Server Management Studio From http://msdn.microsoft.com/en-us/library/ee210574.aspx To view the details of a DAC deployed to an instance of the Database Engine: Select

How to query current user's roles

大城市里の小女人 提交于 2019-11-29 17:44:36
问题 I'm looking for a select statement which will retrieve a list of all database roles for my current connection. I want to create a view which will return all roles to a client software, such that the software can adjust its user interface according to the roles (e.g show/hide menu entries etc) 回答1: You should not be using deprecated backward compatibility views (search this page for sysusers, for example). Instead, you should be using sys.database_principals and sys.database_role_members. Keep

bulk insert a date in YYYYMM format to date field in MS SQL table

可紊 提交于 2019-11-29 17:01:58
I have a large text file (more than 300 million records). There is a field containing date in YYYYMM format. Target field is of date type and I'm using MS SQL 2008 R2 server. Due to huge amount of data I'd prefer to use bulk insert. Here's what I've already done: bulk insert Tabela_5 from 'c:\users\...\table5.csv' with ( rowterminator = '\n', fieldterminator = ',', tablock ) select * from Tabela_5 201206 in file turns out to be 2020-12-06 on server, whereas I'd like it to be 2012-06-01 (I don't care about the day). Is there a way to bulk insert date in such format to a field of date type? kind

get all day of month then mapping data to specific date

大憨熊 提交于 2019-11-29 16:48:26
I created a chart that will plot data to show value for present data on specific date with this SQL select substring(TRAN_DATE, 1, 4) MONTH, substring(TRAN_DATE, 5, 2) DATE, count(*) AMOUNT from TA1606 group by TRAN_DATE this is field structure TRAN_DATE char(6) with this create command CREATE TABLE [dbo].[TA16]( [TRAN_DATE] [char](6) NULL, [TERM] [char](16) NULL, ) this my result is MONTH DATE AMOUNT 1606 03 44 but this is just only one row and one day i need to get all day of month in example is 06 June it will query all day in the month then mapping data to date as my result above shown

Getting a “one or more parameters required to run the report have not been specified” error

倖福魔咒の 提交于 2019-11-29 16:42:36
问题 I am building a report that I would like to accept two values from the user, feed those into a query, and find the data associated with those entries. For example, if you had a list of employees, performance measures, and values associated with those; then the user would select an employee name / performance measure, and they would get the scoring information on that employee for that measure. I have two parameters, each being populated from SQL queries getting a distinct list of employee