Mainstream database copy table structure (sqlserver/MySQL/Oracle/Sybase) [syntax Difference Analysis]

Source: Internet
Author: User

Because the database SQL statement in the major products with "dialect", that is, SQL Server Sybase are using T-SQL, MySQL is using standard SQL, Oracle has its own PL/SQL. Due to the differences in dialects, many SQL statements are difficult to transplant, and they are embarrassing in heterogeneous databases. Of course, DBA is nothing more than checking the syntax. But it is inconvenient. Here we will share with you the syntax analysis in the databases where I copied the table structure, that is, the data.

Let's talk about SQL Server's most familiar experience.

-- If there is no new table in the database, such as table A and Table B.

Select * into B from a -- Copy table and Data

Select * into B from a where 1> 1 -- only copy the table structure

-- If table B already exists in the data, it is not applicable.

Insert into B select * from a -- Copy table data, to avoid. Theoretically, table B should have no data. If yes, it may cause a violation of the primary key.

Insert into B select * from a where ID> 10 -- With the where condition, you can specify the data to be copied. This can also be done without a table.

Here, Sybase and sqlserver are the same. Because in a way, Sybase is the prototype of SQL.

 

 

Next is MySQL. The syntax is slightly different.

-- The database does not contain table B.

Create Table B select * from

Create Table B select * from a where 1 <> 1 -- only copy the table structure

-- Tables B are basically the same as those of sqlserver.

Insert into B select * from

 

Oracle is similar to MySQL, but the syntax requirements are more rigorous. Of course, MySQL can also be written like this.

-- The database does not contain table B.

Create Table B as select * from

Create Table B as select * from a where 1 <> 1 -- only copy the table structure

Create Table B like a -- Copy table structure

-- Tables B are basically the same

Insert into B select * from

These are relatively basic SQL statements, but they are also applicable. In the future, we will analyze some other commonly used SQL statements.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.