I got recently one requirement is as.
Q . I have to pass list as a parameter to the procedure in MySql.
Ans:
MySql> Create procedure myProc (ip_txt TEXT)
BEGIN
SQL :=’SELECT * FROM TABLE WHERE SID IN (&ip_txt)’;
PREPARE sql;
EXECUTE sql;
END;
#Cal that procedure
call myProc(“‘1’,’2′”);
Oracle >
DELETE FROM <TABLE NAME> WHERE ROWID NOT IN (SELECT MIN(ROWID) FROM <TABLENAME>
GROUP BY <DUPLICATEDATACOLUMNNAME>) ;
MS-SQL>
If you have identity column on deleting duplicate data table .
DELETE
FROM <TABLENAME>
WHERE ID NOT IN (
SELECT MAX(ID) FROM <TABLENAME>
GROUP BY <DUPLICATECOLUMNDATA1>,<DUPLICATECOLUMNDATA2>)
If you don’t have an identity column on deleting duplicate data table.
SELECT DISTINCT * INTO <NEWTABLE> FROM <DUPLICATEDATATABLE>
Here’s the data type change with default value.
> ALTER TABLE <Table Name>
>ALTER COLUMN <Column Name> (Data Type) [ NOT NULL] CONSTRAINT <constraint Name> (<default data>)
Here’s the data type change.
>ALTER TABLE <Table Name>
>ALTER COLUMN < Column Name> (Data Type)
If the Data is having in the current table column. Add the one more column with respective data type required.
> ALTER TABLE <Table Name>
>ADD <Column Name> <Data Type(length) <NOT NULL> CONSTRAINT <Constraint Name> (<default length>)
Update the data with the existing column data
> UPDATE <Table Name> SET <New column> = <Old column>
> WHERE < Unique Column Id> = <Unique Column Id>
Drop the old column constraint name if its created.
> ALTER TABLE <Table Name >
> DROP CONSTRAINT <Constraint Name>
Drop the old column
> ALTER TABLE <Table Name> DROP COLUMN <Old Column Name>
Finally change the new column name to old column name as its.
> sp_Rename ‘<Table Name>.<This Column Name>’ ,'<To This Column Name>’ , ‘COLUMN’
Thanks,
San
I wanted to copy the entire structure and data
> SELECT * INTO <Destination Table> FROM <Existing Table>
I wanted to copy only the structure
>SELECT * INTO <Destination Table> FROM <Existing Table> WHERE 1=2;