Does MySQL allow you to use whatever the next auto number is in another column in the same query?
Column A (auto Number)
Column B (text)
Column C (int)
Column D (text)
INSERT INTO table VALUES ('','some text','THIS AUTO NUMBER','some text')
We are trying to use our "auto number" as the default value for another field. If this is possible can you share the syntax.
Of course if its not possible I can just run three queries, first insert, query for auto number used, then update, but if the functionality exist it would be helpful.
Thank you for your time.
If I got it right, you need to have the value of one column to be computed based on the just obtained auto incremented identifier. This does not seem to be possible directly, especially if you want that value to be changed afterwards (otherwise a computed column might do the trick).
Several answers are indicated here:
use a trigger is one option, but I would not recommend it for this simple case
OR
create a Transaction, perform the insert and then update using generated auto incremented number
Related
Is it possible in MySQL to define an autoincrement column to be within a specific range while excluding a list of numbers?
For example, I am trying to find a way to define a column to be within 3000-4000 while excluding 3123-3200, 3312-3400.
I am using DBeaver to design a table.
I am new to KNIME and I have a question, I have column splitter node that is outputting one column and one row. This will naturally have one value in the cell. I want to feed this value into a column of a table in KNIME. How do I do this?
I Don't see two way tables in KNIME.
You can use the Cross Joiner node to append the constant column. (There is also the Table Row to Variable and Constant Value Column combination if the constant value is one of the primitive types (String, Double, Int).)
You may need the RowID node to replace/restore the row ids.
I want to know if its possible to automatically fill a column to its max value if the value inside it isn't already at the max value. For example, if I have a column called score that takes an INT(11) and the data in that column is just 23, is there a way I can get it to add a bunch of numbers to the end of it so its size is actually 11 and not 2? so in the end it would look something like 23000000000?
What you ask about is called padding. You could do that at the database schema level, using a varchar column, but I suggest against it for several reason, including no auto-increment numbers. You can easily pad the number as you like while you query the database, for instance using:
SELECT LPAD('columnname',11,'0')
I want to copy or duplicate a row in a table (tblSpills) while defining the the PK column values (2) (tblSpills.Year, tblSpills.Complaint).
I already have a stored procedure that inserts a new row with the custom PK values and every other columns (about 30) is empty. So far I have gotten as far as executing the existing stored procedure to create the new row and grabbed the new PK values as variables for the new Duplicate stored procedure, but I cannot figure out how to copy the remaining columns from one row to the newly created row in the same table.
Thank you for any help you can provide.
You're not telling us anything about what system / database you're using - but just guessing if it should be SQL Server, you could do something like this:
INSERT INTO dbo.tblSpills(Year, Complaint, list all other columns here)
SELECT
#YearValue, #ComplaintValue,
(list of all other columns here)
FROM
dbo.tblSpills
WHERE
(some condition here, e.g. ID = 42 or something)
Basically, you insert a list of columns into the tblSpills table, based on your new values for Year and Complaint, and you take all other column values from that same table from an existing row (based on that WHERE condition you have to define)
For the "other columns": you only need to list those columns that require a value or for which you want to set a specific value. Those columns that already have a sensible DEFAULT constraint defined don't need to be listed - they'll automatically get the defined default value when a new row is inserted.
I am using mysql. Now I want to write that query in which i will give mysql the row number then mysql will data from that column no only.
means..
if i have twenty rows in database but i want to get only 10th no of rows data? so how to write that kind query?
Create an INT field named "ID" that is set to "Auto Increment." This way each row will have a unique ID that you can use to select it. Details about how to do this are located here.
Add a column with the AUTO_INCREMENT flag on it, so that this columns contains the row number for all your rows. MySQL does not really have support for fetching a row by number, only by column value.