Search
 
SCRIPT & CODE EXAMPLE
 

SQL

restart sequence table mysql

  Route::get('/sync_database/', function () {
        // Get all the tables from your database
        //for postgres
        $tables = DB::select('SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name;');
        //For mysql
        // $tables = DB::select('SHOW TABLES');

        // Set the tables in the database you would like to ignore
        $ignores = array('password_resets');

        $altered_tables = array();

        //loop through the tables
        foreach ($tables as $table) {

            // if the table is not to be ignored then:
            if (!in_array($table->table_name, $ignores)) {

                //Get the max id from that table and add 1 to it
                $seq = DB::table($table->table_name)->max('id') + 1;

                // alter the sequence to now RESTART WITH the new sequence index from above (
                    //for MySQL go DB::select('ALTER TABLE ' . $table->Tables_in_db . ' AUTO_INCREMENT ' . $seq);
                    // Tables_in_db
                    //for Postgres go DB::select('ALTER SEQUENCE ' . $table->Tables_in_db . '_id_seq RESTART WITH ' . $seq);)
                    // table_name
                DB::select('ALTER SEQUENCE ' . $table->table_name . '_id_seq RESTART WITH ' . $seq);
 
                array_push($altered_tables, $table->table_name);
            }
        }

        print_r($altered_tables);
    });
Comment

PREVIOUS NEXT
Code Example
Sql :: PROSYS SQL 
Sql :: Show mysql account privilleges 
Sql :: sql dmv to capture updates 
Sql :: mysql load data infile default file location 
Sql :: sql interview query questions 
Sql :: how to combine rows in sql server procedure 
Sql :: how to add mysql to path on termin after installation 
Sql :: meaning of localhost in mysql 
Sql :: check records older than 10 days 
Sql :: como hacer una consulta de un registro que no esta en una tabla en mysql 
Sql :: T-SQL MERGE with condition what is not matched? 
Sql :: mysql does sentance contain word 
Sql :: add mysql database to power bi web 
Sql :: pl sql constraint user function 
Sql :: CREATE PROCEDURE CategoryInsert (IN c02 VARCHAR) BEGIN INSERT INTO Category(CategoryName) VALUES (c02); END; 
Sql :: localhost ERROR 2006 (HY000) at line 1163: MySQL server has gone away 
Sql :: How to fix a collation conflict in a SQL Server query 
Sql :: trigger vérifier stock 
Sql :: check sql query executed wp 
Sql :: sql grant 
Sql :: rollback to in sql 
Sql :: how to type a blank discord messgae 
Sql :: declare row variable sql server 
Sql :: dbms transaction tutorialspoint 
Sql :: drop check command 
Sql :: PostgreSQL random boolean for generate test values 
Sql :: datatype for phone number in sql 
Sql :: importing multiple xml files in azure sql database 
Sql :: Rows, INSERT INTO 
Sql :: sql trim 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =