Adding auto-incremenation on a VARCHAR column on an SQL Server table - sql

I need to alter customer_number column in organisation table so, that it would become auto-incrementable.
As in, when adding rows to the table, this certain column would get bigger number each time. It is not the id column.
Example: If there would be no rows or only rows that have no value on customer_number column, the newly added organisation row would get 1 as the value for its customer_number column. If there would be already for example two rows with values on said column - say 100 and 200 - the new row would get value 201 on that column.
Is that even possible to do by altering an existing table and column?

Related

Make duplicate records in a table in hive

I have a requirement of making the duplicate records in a table from the number specified in a separate table. Given below the example.
Table A1 having many columns along with seg_id column. And Table B1 having many columns along with seg_id column and iteration_no column.
I have to join both the tables using seg_id column and take the value present in iteration_no column. If the value is 5 then I need to duplicate the entire seg_id row in Table A1 into 5 rows without any changes. Could you please help.

Comparison of two tables based on a cross reference of columns in SQL Server

My question is about comparison of fields based on the mapping table SQL Server. In the attached image, I wanted to compare values of Table 1 and Table 2 based on the mapping provided in Table 3. For example, we need to check values of Table 1's Field 1 with Table 2's Field_3_New and other columns likewise. Mapping of these columns to compare is placed in Table 3.
I want to check, whether Table 1's Field 1 values are matching with Table 2's Field 3_NEW's values or not. We came to know that Table 1's Field 1 values have a match with Table 2's Field 3_New values based on the field mapping provided in Table 3. The above is an example scenario, I'm dealing with 40 odd fields like this.

SQLITE3 Insert into the most recent row where 1 column is an exact match

I have this fairly large DB. It contains lots of column. One of the will have a value that I need to select, but the DB has several of that value. How can I insert into a column in the row thats the newest in the DB, with a matching column.
Without knowing the ins and outs of your database, I think you would likely want to select the largest id you have in the auto incrementing row. For instance:
SELECT MAX(UNIQUE_ID) FROM TABLE WHERE MATCHING_COLUMN = MATCHING_VALUE
From there you can take your unique ID and insert into that row.

MS Access - Select records by rows in a table which does not have unique column

I have two non primary key columns as Field1 and Field2 & the first few records in the table are sometimes not required for executuion. One record in the table displays the text 'Code','TotalValue' in field1 and field2 respectively, and I want all the records to be displayed which are available next to this record. How could I write the query to select the records by rows when I don't have unique values in a column.
Eg:
Field1 Field2
Billing Transactional File bt_billing_transactional_20140626_00000806.dat
Number of Records 44
Number of Accounts 8
Code Total Value
OR20111534 -624989
OR20111072 -485300
OR20111053 -8333
OR20111063 -267828
I want all the four records from the above table which are displayed next to record 'Code','TotalValue'. And the row in which the text TotalValue displayed is not static (it can be in 6th or 7th row). If I select the particular records, I can move these into the new table easily.
Note: It wont help even though if I have the unique column. Because the row order may change when order by a column
Thanks

SQL get the value of the unique key count for some table

i have an SQL table thet have a unique key column, this key increases by 1 when i insert a new record , suppose i deleted all records in this table so if i add a record after deleting all records the count will continue and i would get for example an id of 97 for that record,question is is there a way in sql to get that value of 97 before adding a the record?
Yes. Use IDENT_CURRENT(TABLE_NAME) function to get current identity value of table TABLE_NAME.