LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sql command to add 100 lines with same text in a collumn (https://www.linuxquestions.org/questions/programming-9/sql-command-to-add-100-lines-with-same-text-in-a-collumn-4175668529/)

bmxakias 01-27-2020 12:41 PM

Sql command to add 100 lines with same text in a collumn
 
Hello

I have a table named "data" and a column inside named "site" and i want to add 100 entries with the same data "www.mysite.com"

Inside "site" column to be like:

www.mysite.com
www.mysite.com
www.mysite.com
www.mysite.com
www.mysite.com

etc

How can i do that?

Thank you

Turbocapitalist 01-27-2020 12:45 PM

If this is in regards to one of the Structured Query Language (SQL) databases, then INSERT is what you are looking for. However, the details vary per database. More information is needed.

Please write which database you have, including version, and which distro is it running on, including version.

bmxakias 01-27-2020 12:46 PM

MariaDB 10.3.21
Centos 7.7

Thank you

Turbocapitalist 01-27-2020 12:52 PM

Thanks. There are several ways to get that result.

What have you tried so far in regards to INSERT and a FOR or other loop there? Please show your formula so far so we can see what your approach is, where you are stuck, and what level of complexity you are thinking of.

bmxakias 01-27-2020 01:01 PM

Didn't find anything specific :(

I just found this:

Code:

INSERT INTO data (site) VALUES('www.mysite.com')
but it will not add 100 lines...

Turbocapitalist 01-27-2020 01:04 PM

It's not about finding, it's about learning and writing your own.

INSERT is only part of the solution. You still need a loop to count to 100. Either a FOR loop or a WHILE loop will do, though there are other methods which would work too.

Try looking closely at the two links in the previous post.

dugan 01-27-2020 04:23 PM

Quote:

Originally Posted by bmxakias (Post 6083521)
Didn't find anything specific :(

I just found this:

Code:

INSERT INTO data (site) VALUES('www.mysite.com')
but it will not add 100 lines...

If you really want 100 rows of identical data, then just run that 100 times.

bmxakias 01-28-2020 03:47 AM

Yes but isn't practical to run manually 100 times that command that's why i am looking for a way to do it automatically....

NevemTeve 01-28-2020 05:31 AM

@OP: Has your table got a structure? You know, key-fields and descriptive fields, dependencies, indices, stuff like that?

(My guess is that you have an XY problem, and now your az Z or W)

bmxakias 01-28-2020 06:01 AM

Quote:

Has your table got a structure?
It just has some columns inside....

Quote:

You know, key-fields and descriptive fields, dependencies, indices, stuff like that?
No...

NevemTeve 01-28-2020 06:36 AM

Would you mind listing each and every fields (and their types) in this table?

boughtonp 01-28-2020 09:19 AM

Quote:

Originally Posted by bmxakias (Post 6083515)
I have a table named "data" and a column inside named "site" and i want to add 100 entries with the same data "www.mysite.com"

Why? It sounds like you're not telling us the whole story.

What is the actual problem you're dealing with that will be solved by creating a hundred one-column database rows with the exact same value?


Additionally, what is the output of these two commands:
Code:

show create table `data`
Code:

select * from `data` limit 0,10

bmxakias 01-28-2020 11:02 AM

Quote:

Why? It sounds like you're not telling us the whole story.
I just create a table named 'data' and a i add inside a column named 'site'.

That's the story. Don't know what else is missing.

Quote:

show create table `data`
> OK
> Time: 0,003s

CREATE TABLE `data` (
`data` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1



Quote:

select * from `data` limit 0,10
> OK
> Time: 0,001s

Empty...

TB0ne 01-28-2020 11:11 AM

Quote:

Originally Posted by bmxakias (Post 6083816)
I just create a table named 'data' and a i add inside a column named 'site'. That's the story. Don't know what else is missing.
Code:

CREATE TABLE `data` (
  `data` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Empty...

You created a table, but you have not inserted any data into it. Since you've been pointed to the pages showing you how to do an insert, can you not write a simple bash script that loops 100 times to perform this??
Code:

for i in {1..100}
do
 <command>
done

Not harder than that...and this sounds suspiciously like homework.

michaelk 01-28-2020 11:40 AM

For anyone that has not used Mariadb just typing in <command> is like for any old timer the cartoon that has an equation on the left and right in in the middle the saying "and then a miracle happens"...

From a practical standpoint a database table with a single column that contains the same data is useless since there is no way to "address" a single row. I assume this is why NevemTeve asked the question. So what you trying to accomplish?


All times are GMT -5. The time now is 02:53 PM.