LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 12:41 PM   #1
bmxakias
Member
 
Registered: Jan 2016
Posts: 254

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, 12:45 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
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, 12:46 PM   #3
bmxakias
Member
 
Registered: Jan 2016
Posts: 254

Original Poster
Rep: Reputation: Disabled
MariaDB 10.3.21
Centos 7.7

Thank you
 
Old 01-27-2020, 12:52 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
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, 01:01 PM   #5
bmxakias
Member
 
Registered: Jan 2016
Posts: 254

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 01:35 PM.
 
Old 01-27-2020, 01:04 PM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
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, 04:23 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
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, 03:47 AM   #8
bmxakias
Member
 
Registered: Jan 2016
Posts: 254

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, 05:31 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@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, 06:01 AM   #10
bmxakias
Member
 
Registered: Jan 2016
Posts: 254

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, 06:36 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

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

Rep: Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545Reputation: 2545
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, 11:02 AM   #13
bmxakias
Member
 
Registered: Jan 2016
Posts: 254

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 11:04 AM.
 
Old 01-28-2020, 11:11 AM   #14
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
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, 11:40 AM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
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



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 03:13 PM
[SOLVED] How to describe table structure in PL/SQL developer IDE through sql command? fantasy1215 Programming 2 04-14-2013 08: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 01:58 PM
deleting 100 rows in text file (1-100) via terminal itz2000 Linux - Newbie 5 01-17-2006 11:19 PM
132 collumn terminal frieza Linux - General 1 02-23-2004 10:29 AM

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

All times are GMT -5. The time now is 08:10 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
Open Source Consulting | Domain Registration