LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-27-2020, 01:41 PM   #1
bmxakias
Member
 
Registered: Jan 2016
Posts: 212

Rep: Reputation: Disabled
Question 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
 
Old 01-27-2020, 01:45 PM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,473
Blog Entries: 3

Rep: Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234
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.
 
Old 01-27-2020, 01:46 PM   #3
bmxakias
Member
 
Registered: Jan 2016
Posts: 212

Original Poster
Rep: Reputation: Disabled
MariaDB 10.3.21
Centos 7.7

Thank you
 
Old 01-27-2020, 01:52 PM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,473
Blog Entries: 3

Rep: Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234
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.
 
1 members found this post helpful.
Old 01-27-2020, 02:01 PM   #5
bmxakias
Member
 
Registered: Jan 2016
Posts: 212

Original Poster
Rep: Reputation: Disabled
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...

Last edited by bmxakias; 01-27-2020 at 02:35 PM.
 
Old 01-27-2020, 02:04 PM   #6
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,473
Blog Entries: 3

Rep: Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234Reputation: 2234
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.
 
1 members found this post helpful.
Old 01-27-2020, 05:23 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 9,422

Rep: Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182Reputation: 4182
Quote:
Originally Posted by bmxakias View Post
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.
 
Old 01-28-2020, 04:47 AM   #8
bmxakias
Member
 
Registered: Jan 2016
Posts: 212

Original Poster
Rep: Reputation: Disabled
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....
 
Old 01-28-2020, 06:31 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,997

Rep: Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443
@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)
 
Old 01-28-2020, 07:01 AM   #10
bmxakias
Member
 
Registered: Jan 2016
Posts: 212

Original Poster
Rep: Reputation: Disabled
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...
 
Old 01-28-2020, 07:36 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,997

Rep: Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443Reputation: 1443
Would you mind listing each and every fields (and their types) in this table?
 
Old 01-28-2020, 10:19 AM   #12
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 255

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by bmxakias View Post
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
 
Old 01-28-2020, 12:02 PM   #13
bmxakias
Member
 
Registered: Jan 2016
Posts: 212

Original Poster
Rep: Reputation: Disabled
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...

Last edited by bmxakias; 01-28-2020 at 12:04 PM.
 
Old 01-28-2020, 12:11 PM   #14
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,342

Rep: Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040Reputation: 6040
Quote:
Originally Posted by bmxakias View Post
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.
 
1 members found this post helpful.
Old 01-28-2020, 12:40 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,559

Rep: Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158Reputation: 3158
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?
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dataset is in one collumn - how to split it into two c. ? sayhello_to_the_world General 2 11-09-2013 04:13 PM
[SOLVED] How to describe table structure in PL/SQL developer IDE through sql command? fantasy1215 Programming 2 04-14-2013 09:20 PM
[SOLVED] bash: sort lines in 2 files so that equal lines are at the same line number... masavini Programming 10 06-21-2012 02:58 PM
deleting 100 rows in text file (1-100) via terminal itz2000 Linux - Newbie 5 01-18-2006 12:19 AM
132 collumn terminal frieza Linux - General 1 02-23-2004 11:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration