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
Related
This question already has answers here:
Why does this Oracle DROP COLUMN alter the default value of another column?
(1 answer)
Oracle bug when adding not nullable columns with default
(2 answers)
Closed 1 year ago.
I have a table with some other columns and preexisting data in my development database. I need to add four more columns to store data for a new feature.
I've added four new columns to this table with the following commands:
alter table my_table add (pin_validacao_cadastro varchar2(6 char) default '000000' not null);
alter table my_table add (tentativas_validacao_pin number default 0 not null);
alter table my_table add (codigo_bloqueio number default 1 not null check (codigo_bloqueio in (0, 1, 2)));
alter table my_table add data_validacao_cadastro date;
Then, I've discovered that the first definition needed to change because the default value should be another value. Then, I've dropped the first column (pin_validacao_cadastro).
alter table my_table drop column pin_validacao_cadastro;
Suprisingly enough, before I try to recreate the first column with the correct default value, I've noticed the second column (tentativas_validacao_pin) now is altered and all the values are NULL, when it should to be 0.
Then, I've dropped the second column (tentativas_validacao_pin) to recreate it and fix the corruption.
alter table my_table drop column tentativas_validacao_pin;
But wait! Before I've had the chance to recreate it, I've noticed that all values of the third column (codigo_bloqueio) are equal to 0. Before the DROP command, all values of this column were equal to 1 (the default value for this column).
What am I missing here? Is this supposed to happen? It seems that the default value of the dropped column is being applyed to the next existing column.
Since the problem ocurrs using diferent database tools (sqldeveloper, sqlplus, PlSqldeveloper) I think that it is something related to oracle database.
Can anyone explain what is happening?
I'm using Oracle 11G.
This question already has answers here:
Can a sql server table have two identity columns?
(9 answers)
Closed 3 years ago.
I need to set 3 columns (idUser, idLab, idProfile) as identity, but when I change one of them all the others set identity as "No" and only the latest one sets to "Yes".
Already checked its data type and all are set to "int"
This is because you can have only one column as an identity column in your table.
Please refer Can a sql server table have two identity columns? also.
We really do not need multiple Identity column in a table as we can always get the value of the other two columns from the one Identity column. Here, in this case, idLab and idProfile values same as idUser.
So, if I set idUser to be an identity column, it should suffice for me.
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 6 years ago.
I've created a sequence in my Oracle database. It will increment by 1 every time when i started my application and inserted in the table. The table look like this:
create table COUNTERS_DELEGATION
(
counter_id NUMBER not null,
counter_number LONG not null,
current_date NUMBER not null
)
In the field current_date i will insert the current year.
My question is: When the year increment for example from 2016 to 2017 i want to start my sequence again from initial value 1. Is this possible?
If I understand your request correctly, you want to reset the sequence when the value of the sequence gets to 2017.
If so, I think you'll need to drop and recreate the sequence:
DROP SEQUENCE sequencename;
CREATE SEQUENCE sequencename
MINVALUE 1
MAXVALUE 2017
START WITH 1
INCREMENT BY 1
CYCLE;
This question already has answers here:
How to check if a string is a uniqueidentifier?
(15 answers)
Closed 8 years ago.
I have a column which is of type nvarchar, once the row is processed it updates it with a unique identifier. I need to insert the values other than GUID and NULL into a different table. Is there any built in function to determine whether the value in the column is unique identifier?
I found a way to check it:
SELECT 1 WHERE #StringToCompare LIKE REPLACE('00000000-0000-0000-0000-000000000000', '0', '[0-9a-fA-F]');
or you could see this page for more solutions:
How to check if a string is a uniqueidentifier?
I think There is no such functions, which will determine weather Field is unique / repetitive
only Primary Key constraints / Primary Key to the table will (decides / checks) UID or Not-a- UID .