Ok - I have two tables that are relational. I have been inserted data into the tables because of testing. I also have been deleting data. My question is how do I reset the auto-incremented Primary key values. For example: Primary key of table one is bizID. Well there are only 3 record currently in the table. The bizIDs are 1-3. If I insert another record the bizID will be 88 because that was the next auto-incremented number. I obviously deleted the other records. I want to start the primary key value over from zero. How do I accomplish this? thnks
Since upgrading from SQL Server Management Studio 2008 R2, I've noticed that it no longer autosaves queries that have not been manually saved first. If a file has been manually saved the autorecover files end up in the following directory:
%appdata%MicrosoftSQL Server Management Studio11.0AutoRecoverDatSolution1
However, I have ended up in the situation where I have unsaved queries when my computer has crashed and have not been able to recover them.
I have also found references to .sql files stored in temp files in the following directory, but the files here seem to be very haphazardly caught:
I have a table in my db that has an identity column as the primary key. I have deleted all the data and have tried to use truncate table on it to reset the identity column. The table has a number of foreign key constraints so it will not truncate. Is there any way to reset the indentity column without removing the constraints?
FUNCTION [dbo].[fn_concat_boxes](@item varchar(10), @week int, @type char(1)) RETURNS VARCHAR(100) AS BEGIN
DECLARE @Output varchar(100)
SELECT @Output = COALESCE(@Output + '/', '') + CAST(quantity AS varchar(5)) FROM flexing_stock_transactions WHERE item = @item AND week = @week AND firm_or_commission = @type GROUP BY quantity ORDER BY quantity
gives the same output every time it is called, despite different parameters passed. @Output does not change as expected.
Hi, consider my table, s.no priority status 1 2 pending 2 3 pending 3 0 completed 4 1 pending 5 0 completed Now, if I insert a record as, 6 1 pending the priority must be reset as follows, s.no priority status 1 3 pending 2 4 pending 3 0 completed 4 2 pending 5 0 completed 6 1 pending Im using c# and sql server. How can i do it? Thanks, Jasmeeta.
I have a few SQL tables that use an auto incrementing integer key field, ie it has 'is identify' set to yes The tables have been used for testing while the application was developed. I plan to delete all data from these tables when the application goes live. Is there a way to start SQL counting from 1 again without deleting and re-creating thr tables?
I have a SQL data source triggered with this code: string searchstring = TextBox2.Text; SqlDataSource1.SelectCommand = "mod_search_all_sel"; SqlDataSource1.SelectParameters.Add("search_str", searchstring); SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; The second time this fires however, the SelectParameters.Add function creates another paramter and the stored procedure blows up. How do I do a reset like in old Classic ASP where you would set the DS = Nothing?
In my application , DB has a large table. I write a small program to clear the table whenever the size of table is over 50 MB. At that time , I want to reset identity as 1. How can I do that? Currently , my program delete old table and generate a new one with the same schema when the table is too large.But this is kind of ugly.
This morning I made a change to two tables in my live system. All I did was add a new column in each called 'suspense' with a data type of bit and a default value of '0'.
When the users started using the system they noticed that the record ID numbers had reset and were starting from 1 and going up 2, 3, 4 etc. The last good id number was about 20500. The id columns are set as primary key with identity and increment of 1.
This shouldn't happen should it? Is it a bug? I never touched the ID column, just added the new one.
I have build an application on top of SQL Server 2005 and i am using microsoft driver. My application stops periodically becoz of Database Connection Loss and I get the following exception
com.microsoft.sqlserver.jdbc.SQLServerException: An exception occurred during the DBComms.transmit operation. Exception:Socket closed. Context:(5) [Thread[Thread-55,5,main], IO:7e2dc, Dbc:null]. 10:06:14:703 AM at com.microsoft.sqlserver.jdbc.SQLServerException.ma keFromDriverError(Unknown Source) 10:06:14:703 AM at com.microsoft.sqlserver.jdbc.DBComms.transmit(Unkn own Source) 10:06:14:703 AM at com.microsoft.sqlserver.jdbc.IOBuffer.sendCommand( Unknown Source) 10:06:14:703 AM at com.microsoft.sqlserver.jdbc.SQLServerStatement.se ndExecute(Unknown Source) 10:06:14:703 AM at com.microsoft.sqlserver.jdbc.SQLServerStatement.do ExecuteQuery(Unknown Source) 10:06:14:703 AM at com.microsoft.sqlserver.jdbc.SQLServerPreparedStat ement.executeQuery(Unknown Source)
Unable to find the exact reason for the above problem. Pl advice
I'm trying to create a trigger that will clear the "checked" field when all items with the same classification have been checked.
The purpose of this is to do cycle counting of inventory, which is when you count the stock levels of a proportion of stock that have the same classification.
The checked field will be used to record the date it was lasted checked and will cleared once all stock have counted, putting back into the pool of stock to be counted.
Therefore, the trigger is suppose to count the number of rows that share the same classification as the amended row, and compare that with the number of rows in that classification, that have a date in the checked date field. When the two values are the same, reset all the checked dates to blank.
But when I tested it, nothing happened ...
ALTER TRIGGER [dbo].[UDEF_Last_Checked_Reset] ON [dbo].[ASC_PMA_TBL] AFTER INSERT AS BEGIN DECLARE @PartOnly varchar(16) -- Part Number DECLARE @Rev varchar(4) -- Part Revision DECLARE @PartCode as varchar(2) -- Part Classification DECLARE @Last_Checked as datetime -- Checked Date
this procedure resets the business day to one for every month. It works fine except for the month of October. any idea or suggestions?
DECLARE @i INT SET @i = 1 DECLARE @DateID INT, @DtTimeD DATETIME, @LASTDAY DATETIME DECLARE c CURSOR FOR -- -- LASTDAY is the last day of the month -- the counter will reset to 1 on the first of each month -- SELECT DateID, DtTimeD, DATEADD(dd, -DAY(DATEADD(m,1,DtTimeD)), DATEADD(m,1,DtTimeD)) 'LASTDAY' FROM D_DATE WHERE WkDayIn = 'Yes' AND HolidIn = 'No' OPEN c FETCH NEXT FROM c INTO @DateID, @DtTimeD, @LASTDAY WHILE @@FETCH_STATUS = 0 -- -- update the business day in D_DATE -- BEGIN UPDATE D_DATE SET BusDay = @i WHERE DateID = @DateID -- -- reset the counter to 1 if it's the last day of the month -- IF @DtTimeD = @LASTDAY SET @i = 1 ELSE SET @i = @i + 1 -- IF @@ROWCOUNT = 500 COMMIT -- FETCH NEXT FROM c INTO @DateID, @DtTimeD, @LASTDAY END CLOSE c DEALLOCATE c GO
I use Microsoft SQL Server and also I have several tables. One table has ID like PK, and name. ID use autoincrement number mode, and now when I want start form one but not from 156 or like that. I don't know how? And also when I delete all data from table an run my apllication and add something in table, it starts form last number, not from one.
We are about the deploy our project. We made many testing such as Random data insertion etc. Some tables have autoincrement column, and their numbers reached 3,000,000. After testing, we delete all data in database. Now question is how can we truncate all tables, and make fresh start. We may use TRUNCATE query but it is boring and giving errors some time. Is there way to reset whole database, and make a fresh start, like no data entered before.????
Sorry if this is a dumb question, but I am new to SQL Server and trying a simple cursor. Works fine the first time I execute, but then @@Fetch_Status stays at -1 and it will not work again. If I disconnect and then connect it will work once again. What I am doing wrong?
Hi, I have red this thread while I was searching an answer to my problem. Basically when you develop an app. you do some testing to check if everything is fine. When the testing is done you have primary key seeds starting from a number x which is not 1, as it is when the db is newly created. I read about the truncate instruction (which I knew from mysql) but I can't perform the query because of the presence of a foreign key constraint in another table.
So I thought, maybe there is a way to tell the DB engine to disable FK checks while I do the truncation, but I can't find it in the documentation.
So the question is: using SQL EXPRESS what is the quickest way to reset the db state to its initial state, where all the primary key seeds were 1?
thanks in advance and sry if this question is already answered somewhere else, I searched but I didn't find a solution.
Hi to all, I'd like to know how reset a table, that is I've build an applicationa with VB express, added a DataBase (DB.mdf) and created a table. In this program I add and remove records to the table. There is also a Primary Key (auto-increment). I'd like to know how I can reset the table, that is delete all record and restart from 1 the primary key.
But when I click the button....the validation-controls executes before...so instead for "clearing" the page (reload it without postback) the validation-messages shows that I have forgott to write in som textboxes....
Regarding this post: http://forums.microsoft.com/TechNet/showpost.aspx?postid=2111183&siteid=17
This could be the follow up of that post, but I thought it would be a good idea to open a new post to discuss the ReportViewer.Reset() method.
This is the background:I was getting a "Execution '' not found" error when generating reports, VDeepak wrote something about ReportViewer.Reset() as a solution for this, so I tried with it.
At my workstation, running the project with VS2005 it worked flawlessly. Nevertheless, when I updated the files on the server I got an exception: "method ReportViewer.Reset() not found". Apparently, this was because of an outdated dll: Microsoft.ReportViewer.WebForms.dll. In other post, somebody told this could be solved installing the SQL Server 2005 SP1, I did it with no success... I found a SP2 was launched recently, so I downloaded installed it... Now another exception: a "http bad request exception". Desperate, I removed the ReportViewer.Reset() line from the code and uploaded the files to the server again. This time, everything went ok again, actually, I havn't found the freaking "execution '' not found" exception.
There are two questions here:
1 - What exactly does ReportViewer.Reset() method do? and why the same code could be failing on the server when it was working ok in the workstation (believe me, I tried everything, the only diference is this method). 2 - By chance, could the "Execution '' not found" error be fixed with the SP2??? I searched the change log and found nothing about it.
Hi,i m using vwd2005 express and sql express.i've created a table in sql express and set id fied to primary key and set identity to yes.now when i add a record a the id is auto generated this way 1,2,3,4....but when i delete these records and add the new record.the id column now adds a new id as 5 then 6,7 etc.but i want the id to generate from 1,2,3 again..how can this be done?any idea?thanks. jack.