Adding to the Where clause of an Update in LinQ-to-Entities - sql

Let's say I have a table called Product, with three columns: Id, CustomerId, Name. Id is the primary key. The schema is outside of the control of my group, and we now have a requirement to always provide CustomerId as a parameter for all queries (selects, updates, deletes). It's a long story I'd rather not get into ... it involves triggers :-P
So my question is, when I have an attached entity in LinqToEntities, and I want to save some updates (say I'm updating the name in this case). How can I get it to generate the SQL:
update Product set Name = #Name where Id=#Id and CustomerId=#CustomerId
Where the customerId parameter is included in the where clause in addition to the primary key.
Thanks :-)

Does the CustomerId help uniquely identify the row past #Id? I didn't really follow the "triggers" bit, since the predicate used for the update is not known by the trigger. Or you do want to re-update the CustomerId each time (detectable from UPDATE(...) in the trigger)
The easiest option is to do it as object updates:
var qry = from product in model.Products
where Id == #Id && CustomerId == #CustomerId
select product;
foreach(Product p in qry) {
p.Name = #Name;
}
model.SaveChanges(); // or whatever the method is in EF
If you know you are expecting one record, you could use:
Product prod = (from product in model.Products
where Id == #Id && CustomerId == #CustomerId
select product).Single();
prod.Name = #Name;
mode.SaveChanges(); // ditto
You might also be able to write it as Entity-SQL, but I'm not sure I'd bother, personally... (update: I've just checked, and I don't think Entity-SQL includes DML, so no, you can't - you'd have to use either the above, or a regular SQL command/SPROC)

One way would be to use a stored proc to do the update. This gives you complete control over the SQL.
Another way is to add the CustomerId to the entity key.

Related

Update SQL Server table with one time use values from another table

I have a table of users that has the usual suspects, name, email, etc. As the users complete an activity (queried from another table), I need to award them a gift card code.
update users
set giftcardcode = 'code from other table'
where email in (select email from useractivity where necessary conditions are met)
I have a table of unique gift card codes that are unique, one-time use codes. So I need to update my user table, setting the award code field equal to a distinct, unused gift card code from the gift card code table. Then I need to mark the 'used' field in the gift card table to 'Y'.
The goal is to do this with SQL and not any programming. I'm stumped.
I think there is a Many To Many relationship between User table and Activity table.
So, you can use a trigger to execute a query when update.
Each time a row will be updated in the Activity table, the trigger will do something.
It will UPDATE the User table by adding a new gift code.
I think you can add an attribute in your GiftCode table to easily check if the code as already been used. An you can get an unused code like that :
// Retrieve an unused code based on a BIT attribute.
SELECT TOP 1 [Code] FROM [GiftCode] WHERE IS_UNUSED = 1;
Don't forget to update this Gift code after using it.
You can use a SELECT statement including a sub SELECT statement to get a code too :
// Retrieve an unused code based on User table used codes.
SELECT TOP 1 [Code] FROM [GiftCode] WHERE [Code] NOT IN (SELECT [Code] FROM [User]);
It works well if you don't have too much users.
Otherwise , the first statement will be more efficient.
Don't forget to update the User table.
Now you can easily use one of these previous statement in a UPDATE statement.
It will be something like that :
UPDATE [User] SET [Code] = (
SELECT TOP 1 [Code] FROM [GiftCode] WHERE [Code] NOT IN (
SELECT [Code] FROM [User]))
WHERE USER_ID = // ...;
You can perform this in a trigger.
You can use a stored procedure, it's more efficient and will wrap all the SQL code in a compiled function. Then you can call it in your trigger.
You can execute a stored procedure in a job (see SQL Server Agent jobs) too.
create a Trigger on your table for update and do what you want inside it using inserted and deleted

Remove duplicate lines from SQL Server table

Someone deployed a SQL table with the schema
ConfigOptions
name VARCHAR(50)
value VARCHAR(50)
and the following logic for saving options:
int i = ExecuteNonQuery("UPDATE ConfigOptions SET value=#value WHERE name=#name");
if(i==0) i = ExecuteNonQuery("INSERT INTO ConfigOptions (name,value) (#name,#value)");
We now saw that this table is littered with duplicates, and we want to change this.
As far as I can tell, the logic is: whenever the UPDATE affected zero rows, another row is inserted. If I am not mistaken, this can be caused by:
a row by the name of #name does not exist or
the row exists, but already contains value #value
So, all rows with same name should be full duplicates. If now, something is completely wrong (and behaviour may be undefined).
Now I have to fix this problem of duplicates, so I want to add a PK on name. Before I can do this, I have to remove all rows with duplicate names, only keeping one of each.
In the installer (only the installer is allowed to change schema), I only have SQL queries at hand, so I can't do it with C# logic:
Dictionary<string, int> dic = new Dictionary<string, int>();
SqlDataReader sdr = ExecuteReader("SELECT name,COUNT(value) FROM ConfigOptions GROUP BY name HAVING COUNT(value)>1");
while (sdr.Read()) dic.Add(sdr.GetString(0), sdr.GetInt32(1));
sdr.Close();
foreach (var kv in dic) {
AddParameter("#name", System.Data.SqlDbType.VarChar, 50, kv.Key);
ExecuteNonQuery("DELETE TOP " + (kv.Value - 1) + " FROM ConfigOptions WHERE name=#name");
}
ExecuteNonQuery("ALTER TABLE program_options ADD PRIMARY KEY (name)");
Is there a way to put this into SQL logic?
Using %%physloc%%, the phys(ical) loc(ation) of the row, should do the trick:
DELETE FROM ConfigOptions
WHERE %%physloc%% NOT IN (
SELECT MIN(%%physloc%%)
FROM ConfigOptions
GROUP BY name);
After this cleanup, you can add the primary key to the table.
NOTE: this will leave you with only one row for every name. If the value column is different in two records with the same name, you will lose the newest record. If you want to change this, use GROUP BY name, value.

Correct this sql statement for Insert into, select, delete

INSERT INTO Checkout(ProductID, MemberID, Quantity)
SELECT ProductID, MemberID, Quantity
FROM Cart
WHERE (MemberID = MemberID)
DELETE FROM CART WHERE (MemberID = MemberID)
The sql statement is workable until the Select, WHERE part but once I add the delete statement then the error (syntax error missing operator in query expression) comes out. The second MemberID is a value I gave for first MemberID parameter. Please help me to solve this as after I transfer the data from first table to second table then I need to delete the data from first table.
[Edit] Thanks to you all suggestions and now I realized that for WHERE (MemberID = MemberID)
will import entire table to new table and this statement also will delete the entire table contents. What can I do to make sure that the sql statement only delete the particulars members item?
Main Page>Member login page>Buy something>Item stored in shopping cart database (with member id)>display only particular member's bought item in shopping cart> proceed to checkout(only display that member item, delete shopping cart item)
The problem is with the second "MemberID". This needs to be a constant or have a variable name that doesn't conflict with the field name. A number of techniques for disambiguation are shown in a related SO post: How do you avoid column name conflicts?
You didn't mention what version of SQL Server you're using - but you might be able to use the OUTPUT clause for the DELETE statement to achieve what you're looking for. The OUTPUT clause was introduced in SQL Server 2005, so if you're on 2005 or newer, this code snippet should work for you:
Try this:
DELETE FROM dbo.CART
OUTPUT deleted.ProductID, deleted.MemberID, deleted.Quantity
INTO dbo.Checkout(ProductID, MemberID, Quantity)
WHERE MemberID = #MemberID
Basically this runs the DELETE statement against your dbo.Cart table, and it captures what rows have been deleted; those are then in turn inserted into the dbo.Checkout table.
Also - that condition in the WHERE clause seems quite funny - basically, this will select and thus delete all rows from your table......
Update: I'm assuming you somehow store the relevant member's ID in #MemberID and use that to select the rows to delete from the dbo.Cart table..
Store your passing data to a newly declared variable and use that variable to everywhere as below, this will work fine, thanks
DECLARE #PassedMemberID INT
SET #PassedMemberID = MemberID --Store your passing MemberID here for later use
INSERT INTO Checkout(ProductID, MemberID, Quantity)
SELECT ProductID, MemberID, Quantity
FROM Cart
WHERE (MemberID = #PassedMemberID)
DELETE FROM CART WHERE (MemberID = #PassedMemberID)

SQL Trigger - Maximo Workorders - Supervisor/Owner Initialization

I am working with an IBM Maximo database that issues workorders automatically. When the workorders are issued (aka Inserted into the database workorder table), I would like to auto-assign a supervisor, owner, and owner group based on a set of criteria. This only needs to happen IF the supervisor, owner, and owner group aren't already assigned. Often times a "parent workorder" has the information, but it needs to be copied into the "child" workorders (as you will see in the criteria below). The criteria for ALL of the triggers is:
WHERE status<>'COMP'
AND historyflag=0
AND istask=0
Here is the criteria for the trigger:
-If the Owner Group and Supervisor have a value, skip the record. (Do nothing)
-If the Owner Group and/or Supervisor is blank or null, and the corresponding PARENT Work
Order field is not Null, copy the Owner Group and/or Supervisor from the
PARENT Work Order record.
-If the Parent Work Order Owner Group and/or Supervisor is blank or null, then
assign the Owner Group and Supervisor per the table values below: (I have removed names for security's sake, but all the columns are correct, i.e. B3 is supposed to have SuperA as the supervisor)
Site / OwnerGroup / Supervisor
ABC / #ABCGroup / #ABCSupervisor
DEF / #DEFGroup / #DEFSupervisor
**NOTE:
SITE is not a table column, it is really the first 3 characters of the workorder.location field. For example, the location could be ABC-1234, meaning it is at site ABC, building 1234 (unfortunately, these are NOT stored in separate columns, they are only present together in the location column). In this SQL query, all buildings at a location are serviced by the same ownergroup/supervisor, so all other queries we currently use are using workorder.location='ABC%'
I've done plenty of selects, updates, and stored procedures, but this is my first trigger and want to make sure I don't royally screw up the database! Any and all help is greatly appreciated!
For those unfamiliar with Maximo, the table is:
dbo.workorder
and the fields are:
location,ownergroup,supervisor
UPDATE1:
Here is some additional information that may be of importance.
Locations:
First off, workorder.location will contain values such as ABC-1234, meaning it is at site ABC, building 1234 (though these are NOT separate values, it's combined). In this SQL query, all buildings at a location are serviced by the same ownergroup/supervisor, so all queries use something similar to workorder.location='ABC%'.
Here is what I would like the logic to look like for the final query:
If the supervisor field is missing, first look to see if it has a parent, and if so, does the parent have a supervisor? If not, assign based on the table above.
If the ownergroup field is missing, first look to see if it has a parent, and if so, does the parent have an ownergroup? If not, assign based on the table above.
This is why I am thinking a case statement maybe the best option. Also, I currently have a list of variables such as "#ASupervisor, #B1Supervisor, #B2Supervisor,...etc" so that I can change them in the future if need be. To save a lot of redundant code, is it possible to do something like:
(in this example, location is ABC-1234, ownergroup SHOULD be #ABCGroup, supervisor should be #ABCSupervisor, where #ABCGroup and #ABCSupervisor are set earlier in the code)
If the supervisor field is missing, first look to see if it has a parent, and if so, does the parent have a supervisor (then copy it's supervisor)? If not, assign supervisor X.
Where X = '#' + '(the first three characters of the location)' + 'Supervisor' (in this example, X=#ABCSupervisor)
Is this possible??
UPDATE 2:
I have spoken with the person who asked for this database change and we have changed some thinking here. First, parent locations and child locations should always be the same (if they're not, that's a WHOLE OTHER issue). All sites (first 3 letters of location) should have the same ownergroup and supervisor, so essentially we can just look to see if a workorder entry has a NULL value in either field, then assign it based on the location. I believe the following code will work (but would like someone to review it before I implement it on the system)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER dbo.AutoAssign
ON dbo.workorder
AFTER INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE #ABCSupervisor varchar(30)
DECLARE #DEFSupervisor varchar(30)
DECLARE #ABCOwnerGroup varchar(20)
DECLARE #DEFOwnerGroup varchar(20)
/*EDIT VARIABLES IF FUTURE CHANGES*/
--SET Supervisor values HERE;
SET #ABCSupervisor='JOHNDOE'
SET #XYZSupervisor='JANEDOE'
--SET OwnerGroup values HERE:
SET #ABCOwnerGroup='ALPHATEAM'
SET #XYZOwnerGroup='OMEGATEAM'
--UPDATES
UPDATE dbo.workorder
SET ownergroup='#'+SUBSTR(location,1,3)+'OwnerGroup'
WHERE status<>'COMP'
AND historyflag=0
AND istask=0
AND ownergroup IS NULL
AND location IS NOT NULL
UPDATE dbo.workorder
SET supervisor='#'+SUBSTR(location,1,3)+'Supervisor'
WHERE status<>'COMP'
AND historyflag=0
AND istask=0
AND supervisor IS NULL
AND location IS NOT NULL
END
GO
The only issues I see here are that I do not join of some sort on the "inserted" table so that it only affects those entries (and not the entire table every time). If I could get some help on that, it would be greatly appreciated!!
if you have done some update-statements you are on the right way.
put the virtual table INSERTED in your update-statement and join it with a unique-key, e.g. SerialNo: that would be something like that:
create trigger Trig_WorkOrder for insert, update as
BEGIN
update wo
set location = pwo.location, ...
from dbo.workorder as wo, inserted as i, dbo.parentworkorder as pwo
where wo.serialNo = i.SerialNo -- join with the actual table-entry
and wo.pwo_id = pwo.id -- join with the parentworkorder
and i.ownergroup is null -- do it if new value is empty
and (pwo.ownergroup is not null or pwo.ownergroup <> '') -- do it if parentvalue is not empty
and (pwo.Supervisor is not null or pwo.Supervisor <> '') -- do it if parentvalue is not empty
update wo
set location = pwo.location, ...
from dbo.workorder as wo, inserted as i, dbo.standardworkorder as pwo
where wo.serialNo = i.SerialNo
and wo.location = pwo.location
and wo.ownergroup is null
and (pwo.ownergroup is null or pwo.ownergroup = '')
and (pwo.Supervisor is null or pwo.Supervisor = '')
END
I would sugest to store the default values in a separate table, for convenient joining if the parentvalues are empty.
Put two update-statements inside the trigger an code the where-clause to make sure that only one statement executes...
peace and good luck
If you are using Maximo 7.x, automation scripts can do what you want.
For example, we use an automation script that checks to see if the child work order's field is null. If it is, Maximo will take the parent work order value and fill it. In our case, it a custom field called WOPM1.
WorkOrderSet = mbo.getMboSet("PARENT")
if WorkOrderSet.getMbo(0) is not None:
SUPERVISOR = WorkOrderSet.getMbo(0).getString("SUPERVISOR")
Alternatively, if you have a basic lookup to fill in OwnerGroup and Supervisor based on the first three of the location, you can do a if then type logic to fill in data in the child work order when there is a match. v_location is the variable I have defined for a parent work order location:
if v_location == 'ABC':
mbo.setValue("ownergroup","ABCOwnerGroup")
mbo.setValue("supervisor","ABCSupervisor")
For what you are trying to achieve, I'm not sure using a trigger is the best solution in Maximo - using triggers ignores all MBO business logic. Maybe you could consider customizing MBO classes or using Maximo Escalations to do this taks. Using triggers could also get you in trouble when applying Fix Packs or upgrading Maximo so if you choose to go this way, be sure to backup the triggers before any such action.

Auto Increment after delete in MySQL

I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
After reading other posts on here I've noticed people with the same problem and with varied answers. Some recommend not using this feature, others state it can't be 'fixed'.
I have:
table: course
fields: courseID, courseName
Example: number of records in the table: 18. If I delete records 16, 17 and 18 - I would expect the next record entered to have the courseID of 16, however it will be 19 because the last entered courseID was 18.
My SQL knowledge isn't amazing but is there anyway to refresh or update this count with a query (or a setting in the phpMyAdmin interface)?
This table will relate to others in a database.
Given all the advice, I have decided to ignore this 'problem'. I will simply delete and add records whilst letting the auto increment do it's job. I guess it doesn't really matter what the number is since it's only being used as a unique identifier and doesn't have a (as mentioned above) business meaning.
For those who I may have confused with my original post: I do not wish to use this field to know how many records I have. I just wanted the database to look neat and have a bit more consistency.
What you're trying to do sounds dangerous, as that's not the intended use of AUTO_INCREMENT.
If you really want to find the lowest unused key value, don't use AUTO_INCREMENT at all, and manage your keys manually. However, this is NOT a recommended practice.
Take a step back and ask "why you need to recycle key values?" Do unsigned INT (or BIGINT) not provide a large enough key space?
Are you really going to have more than 18,446,744,073,709,551,615 unique records over the course of your application's lifetime?
ALTER TABLE foo AUTO_INCREMENT=1
If you've deleted the most recent entries, that should set it to use the next lowest available one. As in, as long as there's no 19 already, deleting 16-18 will reset the autoincrement to use 16.
EDIT: I missed the bit about phpmyadmin. You can set it there, too. Go to the table screen, and click the operations tab. There's an AUTOINCREMENT field there that you can set to whatever you need manually.
Primary autoincrement keys in database are used to uniquely identify a given row and shouldn't be given any business meaning. So leave the primary key as is and add another column called for example courseOrder. Then when you delete a record from the database you may want to send an additional UPDATE statement in order to decrement the courseOrder column of all rows that have courseOrder greater than the one you are currently deleting.
As a side note you should never modify the value of a primary key in a relational database because there could be other tables that reference it as a foreign key and modifying it might violate referential constraints.
Try :
SET #num := 0;
UPDATE your_table SET id = #num := (#num+1);
ALTER TABLE `your_table` AUTO_INCREMENT = 1;
That'll reset the autoincremented value, and then count every row while a new value is created for it.
example : before
1 : first value here
2 : second value here
X : deleted value
4 : The rest of the table
5 : The rest of the rest..
so the table will display the array : 1,2,4,5
Example : AFTER (if you use this command you will obtain)
1 : first value here
2 : second value here
3 : The rest of the table
4 : the rest of the rest
No trace of the deleted value, and the rest of the incremented continues with this new count.
BUT
If somewhere on your code something use the autoincremented value... maybe this attribution will cause problem.
If you don't use this value in your code everything should be ok.
You shouldn't be relying on the AUTO_INCREMENT id to tell you how many records you have in the table. You should be using SELECT COUNT(*) FROM course. ID's are there to uniquely identifiy the course and can be used as references in other tables, so you shouldn't repeat ids and shouldn't be seeking to reset the auto increment field.
I came here looking for an answer to the Title question "MySQL - Auto Increment after delete" but I could only find an answer for that in the questions
How to delete certain row from mysql table?
How to reset AUTO_INCREMENT in MySQL?
By using something like:
DELETE FROM table;
ALTER TABLE table AUTO_INCREMENT = 1;
Note that Darin Dimitrov's answer explain really well AUTO_INCREMENT and it's usage. Take a look there before doing something you might regret.
PS: The question itself is more "Why you need to recycle key values?" and Dolph's answer cover that.
What you are trying to do is very dangerous. Think about this carefully. There is a very good reason for the default behaviour of auto increment.
Consider this:
A record is deleted in one table that has a relationship with another table. The corresponding record in the second table cannot be deleted for auditing reasons. This record becomes orphaned from the first table. If a new record is inserted into the first table, and a sequential primary key is used, this record is now linked to the orphan. Obviously, this is bad. By using an auto incremented PK, an id that has never been used before is always guaranteed. This means that orphans remain orphans, which is correct.
There is actually a way to fix that. First you delete the auto_incremented primary key column, and then you add it again, like this:
ALTER TABLE table_name DROP column_name;
ALTER TABLE table_name ADD column_name int not null auto_increment primary key first;
you can select the ids like so:
set #rank = 0;
select id, #rank:=#rank+1 from tbl order by id
the result is a list of ids, and their positions in the sequence.
you can also reset the ids like so:
set #rank = 0;
update tbl a join (select id, #rank:=#rank+1 as rank from tbl order by id) b
on a.id = b.id set a.id = b.rank;
you could also just print out the first unused id like so:
select min(id) as next_id from ((select a.id from (select 1 as id) a
left join tbl b on a.id = b.id where b.id is null) union
(select min(a.id) + 1 as id from tbl a left join tbl b on a.id+1 = b.id
where b.id is null)) c;
after each insert, you can reset the auto_increment:
alter table tbl auto_increment = 16
or explicitly set the id value when doing the insert:
insert into tbl values (16, 'something');
typically this isn't necessary, you have count(*) and the ability to create a ranking number in your result sets. a typical ranking might be:
set #rank = 0;
select a.name, a.amount, b.rank from cust a,
(select amount, #rank:=#rank+1 as rank from cust order by amount desc) b
where a.amount = b.amount
customers ranked by amount spent.
I can think of plenty of scenarios where you might need to do this, particularly during a migration or development process. For instance, I just now had to create a new table by cross-joining two existing tables (as part of a complex set-up process), and then I needed to add a primary key after the event. You can drop the existing primary key column, and then do this.
ALTER TABLE my_table ADD `ID` INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`ID`);
For a live system, it is not a good idea, and especially if there are other tables with foreign keys pointing to it.
I got a very simple but tricky method.
While deleting a row, you can preserve the IDs into another temporary table. After that, when you will insert new data into the main table then you can search and pick IDs from the temporary table. So use a checking here. If the temporary table has no IDs then calculate maximum ID into the main table and set the new ID as: new_ID = old_max_ID+1.
NB: You can not use auto-increment feature here.
You may think about making a trigger after delete so you can update the value of autoincrement and the ID value of all rows that does not look like what you wanted to see.
So you can work with the same table and the auto increment will be fixed automaticaly whenever you delete a row the trigger will fix it.
You can use your mysql client software/script to specify where the primary key should start from after deleting the required records.
Its definitely not recommendable. If you have a large database with multiple tables, you may probably have saved a userid as id in table 2. if you rearrange table 1 then probably the intended userid will not end up being the intended table 2 id.
MYSQL Query
Auto Increment Solution. It works perfect when you have inserted many records during testing phase of software. Now you want to launch your application live to your client and You want to start auto increment from 1.
To avoid any unwanted problems, for safer side
First export .sql file.
Then follow the below steps:
Step 1)
First Create the copy of an existing table
MySQL Command to create Copy:
CREATE TABLE new_Table_Name SELECT * FROM existing_Table_Name;
The exact copy of a table is created with all rows except Constraints.
It doesn’t copy constraints like Auto Increment and Primary Key into new_Table_name
Step 2)
Delete All rows If Data is not inserted in testing phase and it is not useful.
If Data is important then directly go to Step 3.
DELETE from new_Table_Name;
Step 3) To Add Constraints, Goto Structure of a table
3A) Add primary key constraint from More option (If You Require).
3B) Add Auto Increment constraint from Change option. For this set Defined value as None.
3C) Delete existing_Table_Name and
3D) rename new_Table_Name to existing_Table_Name.
Now It will work perfectly. The new first record will take first value in Auto Increment column.
Here is a step to solve your problem.
On your .php file, just add this query given below:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//write the number or id you want to start with the next user in AUTO_INCREMENT
$sql = "ALTER TABLE `table_name` AUTO_INCREMENT = number";
$conn->query($sql);
?>
I hope your problem will be solved.
if($id == 1){ // deleting first row
mysqli_query($db,"UPDATE employees SET id=id-1 WHERE id>1");
}
else if($id>1 && $id<$num){ // deleting middle row
mysqli_query($db,"UPDATE employees SET id=id-1 WHERE id>$id");
}
else if($id == $num){ // deleting last row
mysqli_query($db,"ALTER TABLE employees AUTO_INCREMENT = $num");
}
else{
echo "ERROR";
}
mysqli_query($db,"ALTER TABLE employees AUTO_INCREMENT = $num");
here is a function that fix your problem
public static void fixID(Connection conn, String table) {
try {
Statement myStmt = conn.createStatement();
ResultSet myRs;
int i = 1, id = 1, n = 0;
boolean b;
String sql;
myRs = myStmt.executeQuery("select max(id) from " + table);
if (myRs.next()) {
n = myRs.getInt(1);
}
while (i <= n) {
b = false;
myRs = null;
while (!b) {
myRs = myStmt.executeQuery("select id from " + table + " where id=" + id);
if (!myRs.next()) {
id++;
} else {
b = true;
}
}
sql = "UPDATE " + table + " set id =" + i + " WHERE id=" + id;
myStmt.execute(sql);
i++;
id++;
}
} catch (SQLException e) {
e.printStackTrace();
}
}