This question already has answers here:
Is there an automatic modification time stamp type for Oracle columns?
(6 answers)
How to update a column value in datatype timestamp using Oracle 10G
(1 answer)
Closed 1 year ago.
The below sql statement is not working, seems to be an issue with the "on" statement. I want to add a new column "LastUpdated" that will automatically populate when a new record is inserted or updated.
ALTER TABLE USERS ADD LASTUPDATED DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
This question already has answers here:
How to reset Postgres' primary key sequence when it falls out of sync?
(33 answers)
Closed 3 years ago.
I have a table where the ID sequence goes like 01,02 and so on (I have a few pre-inserted values). When I try to insert a new row there (not specifying the ID explicitly, but rather values for other columns) it tells me that the default value is "1" which is the same as "01" and can't be inserted. How to fix it, thank you!
You can use START WITH argument while creating the sequence.
Example:
CREATE SEQUENCE sequenceName
START WITH 1
INCREMENT BY 1 ;
For more documentation go through the link
This question already has answers here:
How to insert a record with only default values?
(3 answers)
Closed 5 years ago.
SQL Server 2014
Given a table 'test' with the following fields:
id: int. Primary key. Autoincrement by 1.
creation_date: datetime. GETDATE() by default value.
My intention is to insert an empty statement, just to register the event of the insertion. I thought that as the id is an autoincrement and the creation_date has a value by default, a record could be inserted without specifying any value. I know that this can be done by adding a third field and specifying the value in the insertion, but my question is:
Can something like a plain INSERT INTO test be done?
Thanks
INSERT INTO test DEFAULT VALUES
This question already has answers here:
How do I reset a sequence in Oracle?
(18 answers)
Closed 5 years ago.
I am using Oracle SQL. There is a sequence and trigger used for id that increments from 1 every time a new record is added in the table. However if all the records are deleted and new records to be added this table, the id doesn't starts from 1 whilst it starts from the last maximum number of records recorded in the sequence.
Therefore is there a way in TRIGGER statement where I can reset the sequence if the table is empty and new records get imported.
OR do I have to do stored_procedure way, if that then how can i call this using myBatis mapper?
Table (customer_info)
customer_id customer_name customer_location
1 Arbin USA
2 Tim Canada
3 Rachel Australia
Sequence
CREATE sequence customer_id_seq START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
Trigger
CREATE OR REPLACE TRIGGER customer_id
BEFORE INSERT ON customer_info
FOR EACH ROW
BEGIN
SELECT customer_id_seq.NEXTVAL
INTO :new.customer_id
FROM dual;
END;
/
Thank you.
Once You Truncate the Table. The Sequence has to be Reset to 1.
The simplest way to do it it by dropping and re-creating it again.
DROP SEQUENCE customer_id_seq
CREATE sequence customer_id_seq START WITH 1 INCREMENT BY 1 NOCACHE NOCYCLE;
This question already has answers here:
MySQL: How to copy rows, but change a few fields?
(8 answers)
Closed 5 years ago.
How would I copy entire rows within a table and change one value?
insert into user (
user_id,account_id,user_type_cd,name,e_mail_addr,
login_failure_cnt,admin_user,primary_user
)
select * from pnet_user where account_id='1'
But now I want to change 1 to 2 on the inserted entries.
But now I want to change 1 to 3 on the inserted entries.
But now I want to change 1 to .... on the inserted entries.
But now I want to change 1 to 1000 on the inserted entries.
It will copy and write down 1000 times (only changing id ).
I'm not completely sure I understand what you're asking. If you want to copy the records where Account_ID = 1 into new rows and change Account_ID to 2 (or whatever number), this should work for you:
insert into user (user_id,account_id,user_type_cd,name,e_mail_addr,
login_failure_cnt,admin_user,primary_user)
select user_id,2,user_type_cd,name,e_mail_addr,
login_failure_cnt,admin_user,primary_user
from pnet_user where account_id='1'
Basically, replace Account_ID with the value 2. If Account_ID is a varchar, use single quotes around it instead.