Stored procedure for copying data - mysql

I am all new to creating procedures and triggers in MySQL, but have struggled with this over the last couple of days, and it simply will not work. The error messages, that I get from Mysql does not help me any longer.
So I am trying to create a procedure, which I need to run after an update. I will take any updates and store new data in a dynamic created table in another database.
Here it is:
CREATE PROCEDURE get_price_storage_table (IN market_id INT(11), OUT tablename VARCHAR(50))
BEGIN
SET #NUMBER = CEILING(market_id / 100000) * 100000;
SET tablename = CONCAT('price_',#NUMBER);
SET #SQL = CONCAT('CREATE TABLE IF NOT EXISTS data.',tablename,'(
`pk_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`fk_market_id` INT(11) UNSIGNED NOT NULL,
`fk_outcome_type_id` MEDIUMINT(8) UNSIGNED NOT NULL,
`price` DOUBLE NOT NULL,
`status` ENUM(\'enabled\',\'disabled\') NOT NULL,
`created` DATETIME NOT NULL,
PRIMARY KEY (`pk_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8')');
PREPARE stmt FROM #SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;
This need to be triggered after update, where the SQL goes like:
CREATE TRIGGER copy_price_data AFTER UPDATE ON price
FOR EACH ROW
BEGIN
IF NEW.updated <> OLD.updated THEN
SET #market_id = NEW.fk_market_id;
SET #tablename = NULL;
CALL create_price_storage_table(#market_id, #tablename);
SELECT #tablename;
SET #SQL = CONCAT(
'INSERT INTO ',
#tablename,
' (`fk_market_id`, `fk_outcome_type_id`, `price`, `status`, `created`) VALUES (NEW.fk_market_id, NEW.fk_outcome_type_id, NEW.price, NEW.status, NOW())');
PREPARE stmt FROM #SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;
When trying to create the procedure, then I get the following error message from MySQL:
CREATE PROCEDURE get_price_storage_table (IN market_id INT(11), OUT tablename VARCHAR(50))
BEGIN
SET #NUMBER = CEILING(market_id / 100000) * 100000;
MySQL returnerede: Dokumentation 1064 - You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near '' at line 3
I hope someone with greater understanding than me, can point me in the right direction. Thanks.

Change:
CREATE PROCEDURE get_price_storage_table (IN market_id INT(11), OUT tablename VARCHAR(50))
BEGIN
SET #NUMBER = CEILING(market_id / 100000) * 100000;
SET tablename = CONCAT('price_',#NUMBER);
SET #SQL = CONCAT('CREATE TABLE IF NOT EXISTS data.',tablename,'(
`pk_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`fk_market_id` INT(11) UNSIGNED NOT NULL,
`fk_outcome_type_id` MEDIUMINT(8) UNSIGNED NOT NULL,
`price` DOUBLE NOT NULL,
`status` ENUM(\'enabled\',\'disabled\') NOT NULL,
`created` DATETIME NOT NULL,
PRIMARY KEY (`pk_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8')');
PREPARE stmt FROM #SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;
By:
CREATE PROCEDURE `get_price_storage_table`(`market_id` INT UNSIGNED, OUT `tablename` VARCHAR(50))
BEGIN
DECLARE `NUMBER` INT UNSIGNED;
SET `NUMBER` := CEILING(`market_id` / 100000) * 100000;
SET `tablename` := CONCAT('`price_', NUMBER, '`');
SET #`SQL` := CONCAT('CREATE TABLE IF NOT EXISTS ', tablename, '(
`pk_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`fk_market_id` INT(11) UNSIGNED NOT NULL,
`fk_outcome_type_id` MEDIUMINT(8) UNSIGNED NOT NULL,
`price` DOUBLE NOT NULL,
`status` ENUM(\'enabled\',\'disabled\') NOT NULL,
`created` DATETIME NOT NULL,
PRIMARY KEY (`pk_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8');
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8')');
PREPARE `stmt` FROM #`SQL`;
EXECUTE `stmt`;
DEALLOCATE PREPARE `stmt`;
END//
Example:
mysql> DROP PROCEDURE IF EXISTS `get_price_storage_table`;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> DELIMITER //
mysql> CREATE PROCEDURE `get_price_storage_table`(`market_id` INT UNSIGNED, OUT `tablename` VARCHAR(50))
-> BEGIN
-> DECLARE `NUMBER` INT UNSIGNED;
-> SET `NUMBER` := CEILING(`market_id` / 100000) * 100000;
-> SET `tablename` := CONCAT('`price_', NUMBER, '`');
-> SET #`SQL` := CONCAT('CREATE TABLE IF NOT EXISTS ', tablename, '(
> `pk_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
> `fk_market_id` INT(11) UNSIGNED NOT NULL,
> `fk_outcome_type_id` MEDIUMINT(8) UNSIGNED NOT NULL,
> `price` DOUBLE NOT NULL,
> `status` ENUM(\'enabled\',\'disabled\') NOT NULL,
> `created` DATETIME NOT NULL,
> PRIMARY KEY (`pk_id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
-> PREPARE `stmt` FROM #`SQL`;
-> EXECUTE `stmt`;
-> DEALLOCATE PREPARE `stmt`;
-> END//
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
mysql> CALL `get_price_storage_table`(1, #`tablename`);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT #`tablename`;
+----------------+
| #`tablename` |
+----------------+
| `price_100000` |
+----------------+
1 row in set (0.00 sec)
mysql> SHOW TABLES;
+----------------+
| Tables_in_test |
+----------------+
| price_100000 |
+----------------+
1 row in set (0.00 sec)

Syntax errors are to be located to the left (or above) of the place reported in the error message, since the reported place is the first thing that confuses MySQL.
In your case this is the ;
It finishes your CREATE PROCEDURE statement, but MySQL expects more to come, like an END.
Procedures / Triggers / Functions have to be declared with a different delimiter when they consist of more than one statement.
Try like this:
DELIMITER $$
CREATE PROCEDURE whatever()
BEGIN
SELECT 'whatever';
SELECT 'another';
END $$
DELIMITER ;

Related

MySQL Stored Procedure running slow in PhpMyAdmin but fast in Workbench

I have created a stored procedure in MySQL which calls a view to fetch results.
I have executed the stored procedure in MySQL Workbench and its executing in 5 secs.
However, when I run the same in phpMyAdmin it takes 50 seconds.
I have researched and founded that collation of the table columns takes time for that i used the Convert() method on the column but didnt work.
Can anyone help?
Table Schema:
CREATE TABLE `inspection_transactions` (
`id` int NOT NULL,
`point_id` int DEFAULT NULL,
`inspection_id` int DEFAULT NULL,
`instruction_pool_id` int DEFAULT NULL,
`inspection_date` datetime DEFAULT NULL,
`user_id` int DEFAULT NULL,
`result` varchar(255) DEFAULT NULL,
`comment` varchar(255) DEFAULT NULL,
`comment2` varchar(255) DEFAULT NULL,
`inspection_company_transaction_id` int DEFAULT NULL,
`inspection_type` int DEFAULT NULL COMMENT '1:Single, 2:Company, 3:Home '
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
** View **
CREATE
ALGORITHM = UNDEFINED
DEFINER = `hms`#`localhost`
SQL SECURITY DEFINER
VIEW `testingdump`.`inspection_transactions_company_number_grouped_view` AS
SELECT
`inspection_transactions_company_number_view`.`point_id` AS `point_id`,
`inspection_transactions_company_number_view`.`point_name` AS `point_name`,
MONTH(`inspection_transactions_company_number_view`.`inspection_date`) AS `month`,
`inspection_transactions_company_number_view`.`inspection_date` AS `inspection_date`,
`inspection_transactions_company_number_view`.`inspection_id` AS `inspection_id`,
`inspection_transactions_company_number_view`.`instruction_pool_id` AS `instruction_pool_id`,
`inspection_transactions_company_number_view`.`inspection_company_transaction_id` AS `inspection_company_transaction_id`,
`inspection_transactions_company_number_view`.`customer_id` AS `customer_id`,
CONCAT(SUBSTR(`inspection_transactions_company_number_view`.`instruction_pool_name`,
1,
3),
' ',
SUM(`inspection_transactions_company_number_view`.`result`)) AS `result_concat`,
SUM(`inspection_transactions_company_number_view`.`result`) AS `result`,
`inspection_transactions_company_number_view`.`instruction_pool_name` AS `instruction_pool_name`
FROM
`testingdump`.`inspection_transactions_company_number_view`
GROUP BY `inspection_transactions_company_number_view`.`point_id` , `inspection_transactions_company_number_view`.`instruction_pool_id` , MONTH(`inspection_transactions_company_number_view`.`inspection_date`) , `inspection_transactions_company_number_view`.`inspection_company_transaction_id`
ORDER BY `inspection_transactions_company_number_view`.`point_id` , `inspection_transactions_company_number_view`.`instruction_pool_id` , MONTH(`inspection_transactions_company_number_view`.`inspection_date`);
** Stored Procedure **
DELIMITER $$
CREATE DEFINER=`hms`#`localhost` PROCEDURE `company_transactions_number_monthly_pivot`(IN cus_id INT, IN insp_id INT, IN start_date datetime, IN end_date datetime)
BEGIN
SET #sql = NULL;
DROP TABLE IF EXISTS tbl1;
CREATE TEMPORARY TABLE tbl1 AS
( SELECT point_id,point_name, instruction_pool_id, instruction_pool_name, month, convert(result using utf8) collate utf8_general_ci
FROM `inspection_transactions_company_number_grouped_view`
WHERE `customer_id` = cus_id AND `inspection_id` = insp_id and `inspection_date` > start_date and `inspection_date` < end_date
);
SET #sql = CONCAT('SELECT point_name, ', #sql, ' FROM tbl1 GROUP BY point_id');
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;

the count of row( user) for each table begining with cm in the schema

I want all the tables' list with corresponding count of number of NULL entries in column 'user'. I have printed all table's name beginning with cm using
SELECT
TABLE_NAME
FROM
INFORMATION_SCHEMA.TABLES WHERE (TABLE_NAME LIKE 'cm%') ;
but for each table i want to run
SELECT COUNT(1) FROM <TABLENAME> WHERE `create_user` IS NULL
OR `create_time` IS NULL
and print
Create the table below, replacing it with the correct database name:
CREATE TABLE `db`.`tbl_count_null` (
`tableschema` varchar(64) NOT NULL DEFAULT '',
`tablename` varchar(64) NOT NULL DEFAULT '',
`qtd` char(0) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
See if the procedure below meets you:
CREATE DEFINER=`user`#`%` PROCEDURE `nameprocedure`()
BEGIN
DECLARE x, y LONGTEXT;
DECLARE done INT DEFAULT 0;
DECLARE databasesCursor CURSOR FOR
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'cm%';
DECLARE CONTINUE HANDLER
FOR SQLSTATE '02000' SET done = 1;
OPEN databasesCursor;
myLoop: LOOP
FETCH databasesCursor INTO x, y;
IF NOT done THEN
SET #query = CONCAT("INSERT INTO`db`.`tbl_count_null` (tableschema, tablename, qtd) SELECT '",x,"' AS `schema`,'",y,"' AS `table`,COUNT(1) FROM `",x,"`.`",y,"` WHERE `create_user` IS NULL OR `create_time` IS NULL;");
PREPARE stmt FROM #query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END LOOP myLoop;
CLOSE databasesCursor;
END;
After creating the above procedure, call with the command:
call db.nameprocedure;
Verify that the records have been inserted into the table db.tbl_count_null

syntax error in mysql procedure error code 1064

I am trying to write one procedure, i am getting syntax error. I was trying to fix the same with the help of net, but failed.
Here is my stored procedure. Any help please?
The scenario is i am trying to take workspaceid column values from table hotelings and trying to make that value as my column for another table. Then i am trying to update the same column value with ; for a given start and end time of hoteling table in newly created table2.
My two tables are
CREATE TABLE `hotelings` (
`HotelingId` int(11) NOT NULL AUTO_INCREMENT,
`Description` longtext,
`StartDate` datetime NOT NULL,
`EndDate` datetime NOT NULL,
`BookedBy` longtext,
`BookingType` int(11) NOT NULL,
`RepeatType` longtext,
`RepeatDay` longtext,
`ProjectId` int(11) NOT NULL,
`WorkSpaceId` int(11) NOT NULL,
`starttime` varchar(45) DEFAULT NULL,
`endtime` varchar(45) DEFAULT NULL,
PRIMARY KEY (`HotelingId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
CREATE TABLE `hotelingtime` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Time` time DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
and my procedure is:
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `new_procedure`()
BEGIN
SET #sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'MAX(CASE WHEN workspaceid = ''',
workspaceid,
''' then "" ELSE NULL end) AS ',
CONCAT('`',workspaceid,'`')
)
) INTO #sql
FROM sms.hotelings;
SET #sql = CONCAT('CREATE TABLE IF NOT EXISTS table2 AS SELECT t.Time as Time, ', #sql, ' FROM sms.hotelings h, sms.hotelingtime t
GROUP BY t.Time');
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
begin
declare num_rows int;
declare i int;
declare col_name varchar(50);
declare v varchar(10);
DECLARE v_finished INTEGER DEFAULT 0;
-- cursor to fetch column names
DECLARE col_names CURSOR FOR
SELECT column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'table2'
ORDER BY ordinal_position;
-- declare NOT FOUND handler
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;
OPEN col_names;
temp_hotelingloop: LOOP
FETCH col_names INTO col_name;
IF v_finished = 1 THEN
LEAVE temp_hotelingloop;
END IF;
begin
declare starttime time;
declare endtime time;
-- cursor to fetch start and end for a given workspaceid
DECLARE startendTime CURSOR FOR
SELECT starttime, endtime from hotelings
where workspaceid = col_name;
OPEN startendTime;
FETCH startendTime INTO starttime, endtime;
-- i am getting error here and not giving me the result.
SET #sql = CONCAT('update table2 set ''',#col_name ,''' = '';'' where time between ''',#starttime,''' and ''',#endtime,'''');
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
CLOSE startendTime;
end;
SET i = i + 1;
END LOOP temp_hotelingloop;
CLOSE col_names;
end;
select * from table2;
DROP TABLE table2;
END
Any help please?
Thanks in advance
SET #sql = CONCAT('update table2 set ''',#col_name ,''' = '';'' where time between ''',#starttime,''' and ''',#endtime,'''');
You are using #col_name here, but on your declaration missing the #
declare col_name varchar(50);

Mysql use LAST_INSERT_ID in stored procedure

I need to create a table based on the last id inserted into another main table, for this I created the following stored procedure:
CREATE PROCEDURE `sp_create_campaign`
(
IN p_vName VARCHAR(70),
IN p_iIdOper INT(11),
IN p_iIdCount INT(11),
IN p_iIdMoney INT(11),
IN p_cPrefix CHAR(2),
IN p_tComment TINYTEXT,
IN p_iIdUser VARCHAR(32),
OUT p_return_code TINYINT UNSIGNED
)
BEGIN
DECLARE p_campaign INT(11);
DECLARE exit handler for sqlexception
BEGIN
-- ERROR
set p_return_code = 1;
rollback;
END;
DECLARE exit handler for sqlwarning
BEGIN
-- WARNING
set p_return_code = 2;
rollback;
END;
START TRANSACTION;
-- Campaign
INSERT INTO `db_campaign`
(`vName`, `iIdOper`, `iIdCount`, `iIdMoney`, `cPrefix`, `tComment`, `iIdUser`, `dRegister`)
VALUES
(p_vName, p_iIdOper, p_iIdCount, p_iIdMoney, p_cPrefix, p_tComment, p_iIdUser, NOW());
SET p_campaign := LAST_INSERT_ID();
-- Sales
SET #s = CONCAT('DROP TABLE IF EXISTS ', 'db_sale_', p_campaign);
PREPARE stm FROM #s;
EXECUTE stm;
SET #x = CONCAT(
'CREATE TABLE ',
'db_sale_', p_campaign,
"(
`iIdSale` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`dDate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`dSubtotal` DECIMAL(7,2) UNSIGNED NOT NULL DEFAULT '00.00',
`dTax` DECIMAL(7,2) UNSIGNED NOT NULL DEFAULT '00.00',
`dTotal` DECIMAL(7,2) UNSIGNED NOT NULL DEFAULT '00.00',
`iIdMoney` INT(11) UNSIGNED NOT NULL,
`iIdOper` INT(11) UNSIGNED NOT NULL,
`iIdBankCount` INT(11) UNSIGNED NOT NULL,
`iIdGroup` INT(11) UNSIGNED NOT NULL,
`iIdUser` INT(11) UNSIGNED NOT NULL,
`iIdUserReg` VARCHAR(32) NOT NULL,
`dRegister` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`iIdSale`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
PREPARE stm FROM #x;
EXECUTE stm;
COMMIT;
-- SUCCESS
set p_return_code = 0;
END
But the problem is that only inserts the first record and fails to create the table. Where am I failing?
Replace this line: SET p_campaign := LAST_INSERT_ID();
With this one: SELECT LAST_INSERT_ID() INTO p_campaign ;
if you use SET you need = instead of :=
Two things:
Executing DROP will implicitly COMMIT your transaction.
Try adding
DEALLOCATE PREPARE stm;
after each EXECUTE statement.
According to MySQL documentation of last_insert_id()
If a stored procedure executes statements that change the value of LAST_INSERT_ID(), the changed value is seen by statements that follow the procedure call.
Use something like:
SELECT id INTO p_campaign FROM db_campaign ORDER BY id DESC LIMIT 1;
Or:
SELECT max(id) INTO p_campaign FROM db_campaign;

Change auto increment starting number?

In MySQL, I have a table, and I want to set the auto_increment value to 5 instead of 1. Is this possible and what query statement does this?
You can use ALTER TABLE to change the auto_increment initial value:
ALTER TABLE tbl AUTO_INCREMENT = 5;
See the MySQL reference for more details.
Yes, you can use the ALTER TABLE t AUTO_INCREMENT = 42 statement. However, you need to be aware that this will cause the rebuilding of your entire table, at least with InnoDB and certain MySQL versions. If you have an already existing dataset with millions of rows, it could take a very long time to complete.
In my experience, it's better to do the following:
BEGIN WORK;
-- You may also need to add other mandatory columns and values
INSERT INTO t (id) VALUES (42);
ROLLBACK;
In this way, even if you're rolling back the transaction, MySQL will keep the auto-increment value, and the change will be applied instantly.
You can verify this by issuing a SHOW CREATE TABLE t statement. You should see:
> SHOW CREATE TABLE t \G
*************************** 1. row ***************************
Table: t
Create Table: CREATE TABLE `t` (
...
) ENGINE=InnoDB AUTO_INCREMENT=43 ...
How to auto increment by one, starting at 10 in MySQL:
create table foobar(
id INT PRIMARY KEY AUTO_INCREMENT,
moobar VARCHAR(500)
);
ALTER TABLE foobar AUTO_INCREMENT=10;
INSERT INTO foobar(moobar) values ("abc");
INSERT INTO foobar(moobar) values ("def");
INSERT INTO foobar(moobar) values ("xyz");
select * from foobar;
'10', 'abc'
'11', 'def'
'12', 'xyz'
This auto increments the id column by one starting at 10.
Auto increment in MySQL by 5, starting at 10:
drop table foobar
create table foobar(
id INT PRIMARY KEY AUTO_INCREMENT,
moobar VARCHAR(500)
);
SET ##auto_increment_increment=5;
ALTER TABLE foobar AUTO_INCREMENT=10;
INSERT INTO foobar(moobar) values ("abc");
INSERT INTO foobar(moobar) values ("def");
INSERT INTO foobar(moobar) values ("xyz");
select * from foobar;
'11', 'abc'
'16', 'def'
'21', 'xyz'
This auto increments the id column by 5 each time, starting at 10.
You can also do it using phpmyadmin. Just select the table than go to actions. And change the Auto increment below table options. Don't forget to click on start
Procedure to auto fix AUTO_INCREMENT value of table
DROP PROCEDURE IF EXISTS update_auto_increment;
DELIMITER //
CREATE PROCEDURE update_auto_increment (_table VARCHAR(64))
BEGIN
DECLARE _max_stmt VARCHAR(1024);
DECLARE _stmt VARCHAR(1024);
SET #inc := 0;
SET #MAX_SQL := CONCAT('SELECT IFNULL(MAX(`id`), 0) + 1 INTO #inc FROM ', _table);
PREPARE _max_stmt FROM #MAX_SQL;
EXECUTE _max_stmt;
DEALLOCATE PREPARE _max_stmt;
SET #SQL := CONCAT('ALTER TABLE ', _table, ' AUTO_INCREMENT = ', #inc);
PREPARE _stmt FROM #SQL;
EXECUTE _stmt;
DEALLOCATE PREPARE _stmt;
END//
DELIMITER ;
CALL update_auto_increment('your_table_name')
If you need this procedure for variable fieldnames instead of id this might be helpful:
DROP PROCEDURE IF EXISTS update_auto_increment;
DELIMITER //
CREATE PROCEDURE update_auto_increment (_table VARCHAR(128), _fieldname VARCHAR(128))
BEGIN
DECLARE _max_stmt VARCHAR(1024);
DECLARE _stmt VARCHAR(1024);
SET #inc := 0;
SET #MAX_SQL := CONCAT('SELECT IFNULL(MAX(',_fieldname,'), 0) + 1 INTO #inc FROM ', _table);
PREPARE _max_stmt FROM #MAX_SQL;
EXECUTE _max_stmt;
DEALLOCATE PREPARE _max_stmt;
SET #SQL := CONCAT('ALTER TABLE ', _table, ' AUTO_INCREMENT = ', #inc);
PREPARE _stmt FROM #SQL;
EXECUTE _stmt;
DEALLOCATE PREPARE _stmt;
END //
DELIMITER ;
CALL update_auto_increment('your_table_name', 'autoincrement_fieldname');
just export the table with data ..
then copy its sql like
CREATE TABLE IF NOT EXISTS `employees` (
`emp_badgenumber` int(20) NOT NULL AUTO_INCREMENT,
`emp_fullname` varchar(100) NOT NULL,
`emp_father_name` varchar(30) NOT NULL,
`emp_mobile` varchar(20) DEFAULT NULL,
`emp_cnic` varchar(20) DEFAULT NULL,
`emp_gender` varchar(10) NOT NULL,
`emp_is_deleted` tinyint(4) DEFAULT '0',
`emp_registration_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`emp_overtime_allowed` tinyint(4) DEFAULT '1',
PRIMARY KEY (`emp_badgenumber`),
UNIQUE KEY `bagdenumber` (`emp_badgenumber`),
KEY `emp_badgenumber` (`emp_badgenumber`),
KEY `emp_badgenumber_2` (`emp_badgenumber`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=111121326 ;
now change auto increment value and execute sql.