As i have created a table with four attribuites or class have total five case values in each attribuites or class. Now i have added one more attribuites or class, but i dont able to unsderstand how i add values in this attribuites or class for five cases. exm for email at one go.
id name address phone email
1 skhan abc 1123
2 Rkhan def 123
3 Akhan ghi 234
4 Bkhan jkl 343
5 Tkhan mno 234
Do you want to insert multiple rows at once? If so, you can simply append the value lists for the other rows separated by a comma:
insert into yourtablename (name, address, phone)
values ('skhan',' abc', '1123'), # first row
('Rkhan', 'def', '123'); # second row
If not, please clarify your question.
Gud mrng sam , i think i need to clear my question in details as
i have already a table with four attributies such as below having data
|skhan |abc |1123|
|rkhan |def |123|
now i have added new attribute email. now my new table looks like as
|name |address|phone| email
|skhan |abc |1123 |
|rkhan |def |123 |
|bkhan|ghi |2345 |
Now i want to insert the email address for skhan, rkhan and bkhan in one go . which statement should i need to write ??
That depends on where you get the email from. If you just want to do mass updates the usual way would be to do individual updates (I assume that there is an
id column as in your first post)
UPDATE yourtable SET email = 'firstname.lastname@example.org' WHERE id = 1;
UPDATE yourtable SET email = 'email@example.com' WHERE id = 2;
This will work on any DBMS.
In recents versions of MySQL you can use the same SQL you would use to insert the initial values and add an
ON DUPLICATE KEY UPDATE clause:
INSERT INTO yourtablename (id, name, address, phone, email) AS new
VALUES (1, 'skhan',' abc', '1123', 'firstname.lastname@example.org'),
(2, 'Rkhan', 'def', '123', 'email@example.com')
ON DUPLICATE KEY UPDATE email = new.email;
```So that inserts the specified rows if they don’t exist. If it already exists, it updates the
email column with the value from the row we tried to insert.
now i got it i will try the update optiin then let you know thanks!!
hey sam!!, it works . Now i have one more question . Let us suppose we have database school having a table class have
and want to fill this table without typing each row element by excel file i have in which all info of other student. How we will do this ?
MySQL Workbench has an import wizard that can import data from csv or json files. Right click on a table -> “Table Data Import Wizard”.
thanks sam i will try i hope the same is work in Microsoft sql too. Sam actually just give brief intro of myself i m from india and having electrical engg background not from software or computer engg. bcoz of my interest to make some application for my filed i learned SQL, HTML/CSS and Python.
Right now i m making a web based application for Switchgear Sizing project for my company siemens.
If ur comfortable can u please guide me for the same then i will share other details and my approach which i m taking right now.
SQL Server Management Studio has (several) import wizards, too. You find them in the “Tasks” category of the context menu of any database.