Copy MySQL Structure, Clone SQL Table Structure

Create an duplicate table structure from the primary table

      1) CREATE TABLE enquirydetail1 LIKE enquirydetail;

Advertisements

MySql Import a record from another Database

How to import a record from another database table in mysql ?

Same Table Structure in Source and Destination Table

INSERT INTO <TABLENAME> SELECT * FROM <DESTINATION DATABASENAME>.<TABLENAME>

Transfer from Limited Fields

INSERT INTO <TABLENAME> (col1, col2) SELECT (col1, col2) FROM <DESTINATION DATABASENAME>.<TABLENAME>

Transfer from Limited Fields with Condition

INSERT INTO <TABLENAME> (col1, col2) SELECT (col1, col2) FROM <DESTINATION DATABASENAME>.<TABLENAME> where condition.field = condition.value

Mysql update a column with row no

Update a column with record row no in MySQL

  1. Execute the below query in Mysql to update an row no. in the specified column

 

My Sql Query Example 

SET @pos := 0
UPDATE userinfo SET fuserid = ( SELECT @pos := @pos + 1 ) ORDER BY updated_at DESC

  1. @pos -> Variable Name
  2. userinfo -> Table Name
  3. fuserid -> Column Name

 

 

MySql Auto Id unique update

Add Auto ID. Column in existing data’s table  

Step :1

ALTER TABLE `users` ADD COLUMN
(
    `userid` smallint(6) NOT NULL,    
) 

Step : 2 

UPDATE 'users', (SELECT @id := 0) dm
SET userid = (@id := @id + 1)

Step : 3

   Make it as primary field  
   
   Select table (users) > select a column (userid) > click the link primary
 

 

Add New Column in MSSQL

Add a new column in MSSQL 

alter table <<table_name>>
add <<columnname>> <<data type>>

Example :-

alter table employee
add first_name varchar(25)

Get SQL Server Name in MSSQL

How to get MSSQL Server name in MSSQL  ?

select @@servername

How to get user name in MSSQL  ?

SELECT SUSER_NAME() LoggedInUser