CodePudding user response:
The knot posted rate windowCodePudding user response:
Can obtain the maximum or the latest datesSql:='SELECT IDENT_CURRENT (' + QuotedStr (' TableName) +') as NextId ';
CodePudding user response:
VARSTableName sSql: string;
The begin
SSql:='select top (1) the name of the from sys. Objects where type=' 'U' 'order by modify_date desc';
STableName: according to the value of sSql=
SSql:='select top (1) the from + sTableName +' order by id desc;
Perform sSql, that is, get the latest
end;
CodePudding user response:
SSql:='select top (1) the name of the from sys. Objects where type=' 'U' 'order by modify_date desc';STableName: according to the value of sSql=
SSql:='select top (1) the from + sTableName +' order by id desc;
Don't know much about the specific meaning, can elaborate a little???
Now I need to read the latest SQL database records, and record the data in the subsequent operation
CodePudding user response:
You perform in your database itSelect top (1) the name of the from sys. Objects where type='U' order by modify_date desc
Will return a list of recently moved the table name
Sys. Objects: view, in the database table name and update time is stored in the type='u', that is the user table
Select top (1) * from you to get the name of the table of the order by the primary key desc is not the latest data
CodePudding user response:
STableName: according to sSql=value: this sentence is what meaning,If a database table for "ovality measure", table contains ID, ovality, the maximum diameter, minimum diameter, etc., how specific operation
CodePudding user response:
There is a problem, if I query the article in the latest data, how to a a read out, the latest data for other operation?The great god, thank you!
CodePudding user response:
VarQry: TADOQuery;
SSql, sTable, sObjId: string;
The begin
Try
Qry:=TADOQuery. Create (nil);
Qry. Connection:=your Connection;
With qry do
The begin
-- -- -- -- -- -- -- -- -- take the table name
close;
SQL. Text:=
'the SELECT top (1) the OBJECT_NAME (a.O BJECT_ID) AS tableName, a.O BJECT_ID' +
'the FROM sys. Dm_db_index_usage_stats a' +
'the join sys. Tables on b a.o bject_id=b.o bject_id and b.t ype=' 'U' ' '+
'WHERE database_id=7 - (ID number here to write your data)' +
'and a. ast_user_update is not null' +
'order by a. ast_user_update desc';
The open;
If not the Empty then
The begin
STable:=Fields [0]. AsString;
SObjId:=Fields [1]. AsString;
End
The else
exit;
-- -- -- -- -- -- -- -- -- -- take automatically increase the field name
close;
SQL. Text:='select the name from sys. All_columns where object_id=' + sObjId: + 'and is_identity=1'.
The open;
If not the Empty then
The begin
SObjId:=Fields [0]. AsString;
End
The else
exit;
- take the latest record
close;
SQL. Text:='select top (1) * from + sTable +' order by '+ sObjId +' desc ';
The open;
- perform your operations
end;
The finally
If assigned (qry) then freeandnil (qry);
end;
end;
CodePudding user response:
The columns of the database id, a, c, dADOQuery1. Close;
ADOQuery1. SQL. The Clear;
SSql:='select top 1 Id as MaxId from vv_ova order by Id desc';
ADOQuery1. SQL. The Add (sSql);
ADOQuery1. Open;
Edit16. Text:=adoquery1. Fields. [0] value;
Edit17. Text:=adoquery1. Fields [1]. The value;
Can get the maximum id number, and stored in edit16, why can't edit17 get a value, the program runs to edit17. The text in the List index out of bound (1)
My purpose is to get the value of the id number and a great god, help me
CodePudding user response:
In general, have ID in the table since the increase (or decrease) fieldThe latest is that ID=MAX (ID) or ID=MIN (ID) of the
Or table by querying system, as the eighth floor say
However, since you have the demand, why even in the table have no ID?