Sakila -> insert into Film ( mysql WorkBench ) - mysql

I'm trying put a new row in table sakila. film, but I can't see it in the table, I think that not exist, but when execute this statement Works correctly, I don't know what happened
INSERT INTO `sakila`.`film`
(
`title`,
`description`,
`release_year`,
`language_id`,
`original_language_id`,
`rental_duration`,
`rental_rate`,
`length`,
`replacement_cost`,
`rating`,
`special_features`,
`last_update`)
VALUES( 'GUSANO' ,'GUSANO' ,2006,1,1,3,4.99,4 ,19.99, 'G','Trailers','2006-02-15 04:34:33.0');
Result :
21:52:44 INSERT INTO `sakila`.`film` ( `film_id`, `title`, `description`, `release_year`, `language_id`, `original_language_id`, `rental_duration`, `rental_rate`, `length`, `replacement_cost`, `rating`, `special_features`, `last_update`) VALUES( 10010, 'GUSANO' ,'GUSANO' ,2006,1,1,3,4.99,4 ,19.99, 'G','Trailers','2006-02-15 04:34:33.0') 1 row(s) affected 0.015 sec
Image insert :
Image select :

Related

keep getting error trying to add records into table

mysql>
insert into `customers`
( `customerNumber`,
`customerName`,
`contactLastName`,
`contactFirstName`,
`phone`,
`addressLine1`,
`addressLine2`,
`city`,
`state`,
`postalCode`,
`country`,
`salesRepEmployeeNumber`,
`creditLimit`)
values
(497,
'SomeName',
'LastNameSample',
'800-555-1234',
'123 Main St',
'Apt 41',
'Some Town',
'CA',
'96024',
1002,
20000);
Error:
ERROR 1136 (21S01): Column count doesn't match value count at row 1
above is what I have written in order to add a record into a Customer table but I keep getting an error. help me, please?

Is it possible to insert in mysql a combo of words and variable?

Trigger definition:
BEGIN
INSERT INTO `user` (`ID`, `Username`, `Password`, `Online`) VALUES
(NEW.ID, "store_"NEW.ID , 'blablabla', 0);
END
In this trigger I have to insert as username something like store_(id of the new store).
Is it possible to do this and if yes how?
There are 2 ways to concat/append string in SQL
a. Use + operator to join the string
b. Use Concat function.
By using + operator the query would be like below.
BEGIN
INSERT INTO `user` (`ID`, `Username`, `Password`, `Online`) VALUES
(NEW.ID, "store_" + NEW.ID , 'blablabla', 0);
END
By using Concat() function the query would be like below.
BEGIN
INSERT INTO `user` (`ID`, `Username`, `Password`, `Online`) VALUES
(NEW.ID, Concat("store_",NEW.ID) , 'blablabla', 0);
END
Recommended option is use 'Concat' function as syntax is easier to follow, and the code looks cleaner
Use concat function :
BEGIN
INSERT INTO user (ID, Username, Password, Online)
VALUES
(NEW.ID, CONCAT('store_',NEW.ID), 'blablabla', 0);
END

Uknown Column new in FIELD LIST Mysql Trigger

I have the following trigger which is supposed to insert on a trigger table after insert. I keep on getting the following error : Unknown Column Field in List
Below is my trigger :
DROP TRIGGER IF EXISTS `trgr_client_statement_report`;CREATE DEFINER=`uniquelo`#`localhost` TRIGGER `trgr_client_statement_report` AFTER INSERT ON `statement` FOR EACH ROW INSERT INTO trgr_statement
( `amnt_cr`, `amnt_dr`, `approved`, `clnt_id`,`date_added`,`days`, `description`,
`discount`,
`id_2`,
`invoiced`,
`invoice_no`,
`job_card_id`,
`payment_date`,
`payment_status`,
`pymnt_code`,
`pymnt_mthd`,
`qty`,
`rcpt_no`,
`status`)
VALUES
( NEW.`amnt_cr`,NEW.`amnt_dr`,NEW.`approved`,NEW.`clnt_id`,NEW.`date_added`,NEW.`days`,NEW.`description`,NEW.`discount`,NEW.`id`,NEW.`invoiced`,NEW.`invoice_no`,NEW.`job_card_id`,NEW,`payment_date`,NEW.`payment_status`,NEW.`pymnt_code`,NEW.`pymnt_mthd`,NEW.`qty`,NEW.`rcpt_no`,NEW.`status`)
There are some Syntax error in fieldlist. You must use NEW.field not NEW,field : NEW,payment_date
DROP TRIGGER IF EXISTS `trgr_client_statement_report`;
CREATE DEFINER=`uniquelo`#`localhost` TRIGGER `trgr_client_statement_report` AFTER INSERT ON `STATEMENT` FOR EACH ROW INSERT INTO trgr_statement
( `amnt_cr`, `amnt_dr`, `approved`, `clnt_id`,`date_added`,`days`, `description`,
`discount`,
`id_2`,
`invoiced`,
`invoice_no`,
`job_card_id`,
`payment_date`,
`payment_status`,
`pymnt_code`,
`pymnt_mthd`,
`qty`,
`rcpt_no`,
`status`)
VALUES
( NEW.`amnt_cr`,NEW.`amnt_dr`,NEW.`approved`,NEW.`clnt_id`,NEW.`date_added`,NEW.`days`,NEW.`description`,NEW.`discount`,NEW.`id`,NEW.`invoiced`,NEW.`invoice_no`,NEW.`job_card_id`,NEW.`payment_date`,NEW.`payment_status`,NEW.`pymnt_code`,NEW.`pymnt_mthd`,NEW.`qty`,NEW.`rcpt_no`,NEW.`status`)

Import/export tables in mysql

Want to import users from a table(re_user) to another table(pg_users).
Can you help me?
Thnx.
INSERT INTO `pg_users`(`id`, `fname`, `sname`, `status`, `confirm`, `login`,
`password`, `lang_id`, `email`, `date_birthday`, `date_last_seen`,
`date_registration`, `root_user`, `guest_user`, `login_count`, `active`,
`show_info`, `phone`, `user_type`, `access`, `version_message_count`, `rating`,
`about_me`, `social_data`, `date_modified`)
SELECT `id`, `fname`, `sname`, `status`, `confirm`, `login`, `password`, `lang_id`,
`email`, `date_birthday`, `date_last_seen`, `date_registration`, `root_user`,
`guest_user`, `login_count`, `active`, `show_info`, `phone`, `user_type`,
`access`,`version_message_count`, `rating`, `about_me`, `social_data`,
`date_modified` FROM `re_user` WHERE 1
Based on what you disclosed in your comments, that you want to insert data into a table by pulling it from a table in another database, you must be specific as to which database this information is coming from, and going to. Update the DESTINATION_SCHEMA_NAME and the SOURCE_SCHEMA_NAME in my example below and that should resolve the issue. Also, if you are copying everything, there is no need for the where clause in your select statement.
INSERT INTO `DESTINATION_SCHEMA_NAME.`pg_users`(`id`, `fname`, `sname`, `status`, `confirm`, `login`,
`password`, `lang_id`, `email`, `date_birthday`, `date_last_seen`,
`date_registration`, `root_user`, `guest_user`, `login_count`, `active`,
`show_info`, `phone`, `user_type`, `access`, `version_message_count`, `rating`,
`about_me`, `social_data`, `date_modified`)
SELECT `id`, `fname`, `sname`, `status`, `confirm`, `login`, `password`, `lang_id`,
`email`, `date_birthday`, `date_last_seen`, `date_registration`, `root_user`,
`guest_user`, `login_count`, `active`, `show_info`, `phone`, `user_type`,
`access`,`version_message_count`, `rating`, `about_me`, `social_data`,
`date_modified` FROM `SOURCE_SCHEMA_NAME`.`re_user`
This is how you can do that.
Command Line
Import / Export for single table:
Exporting table schema
-> mysqldump -u your_user_name -p your_database_name table_name > test.sql
This will create a file named test.sql and creates table sql command to create table table_name.
Importing data into table
-> mysql -u your_user_name -p database_name table_name < test.sql
Make sure your test.sql file is in the same directory, if not navigate through the path and then run the command.

SQL INSERT into MySQL table where column name includes an apostrophe

Does anyone know how I can perform an SQL INSERT operation into a MySQL table where column names include apostrophes, for example:
INSERT INTO MYTABLE (`id`, `Column'1`, `Column'2`) VALUES...
I have tried things like this but to no avail:
INSERT INTO MYTABLE (`id`, `Column''1`, `Column''2`) VALUES...
INSERT INTO MYTABLE (`id`, `Column\'1`, `Column\'2`) VALUES...
You should be able to just place backticks around the column name:
INSERT INTO MYTABLE (`id`, `Column'1`, `Column'2`) VALUES...
see SQL Fiddle with Demo
create table yourtable
(
id int,
col1 varchar(10),
`col'2` varchar(10)
);
insert into yourtable (id, col1, `col'2`) values
(1, 'test', 'sdfsd'),
(1, 'test', 'gtet')
Just put the name into a variable and use the character 39 for the apostrophe.
Example :
L'oiseau becomes :
Loiseau = 'L' + chr(39) + 'oiseau'
print(Loiseau)
=> L'oiseau