If an SQL data table exists, delete it and create it if it does not exist.

Source: Internet
Author: User

If an SQL data table exists, delete it and create it if it does not exist.

Our commonly used mssql server

Stored Procedure:
Set @ sign = 0;
Select 1 into @ sign from information_schema
Where table_name = 'a' and table_schema = 'tutorial name of the database in which table aa is located ';
If @ sign = 0 then
Create table aa .....
End if;

Command line:
Create table if not exists aa (
Table definition
);

 


There is no such thing as SQL Server in ORACLE.

If exists (select * from dbo. sysobjects where id = object_id (n' [dbo]. [HY_BSCDNM_J] ') and OBJECTPROPERTY (id, n' isusertable') = 1)
Drop table [dbo]. [HY_BSCDNM_J]
GO

Create table .......

To avoid the need to always click SURE, you can refer to the online method to save the trouble of clicking when creating a temporary table.

The script to be collected is completely written, and one-step execution is in place to export the waiting results, saving a lot of time to complete the next Request.

Declare
I integer;
Begin
Select count (*) into I from user_tables where table_name = 'xb _ test001 ';
If I> 0 then
Dbms_output.put_line ('This table already exists! ');
Execute immediate 'drop TABLE xb_test001 ';
Else
Dbms_output.put_line ('This table does not exist ');
End if;
Execute immediate 'create TABLE XB_TEST001 (id int primary key, name varchar (50 ))';
End;

Data is updated when stored

The SQL execution requires three steps:

$ SQL = "if (select * from ips tutorial tats where ip = '2017. 168.0.1 '){
Update ipstats set clicks = clicks + 1 where ip = '192. 168.0.1 ';
} Else {
Insert into ipstats (ip, clicks) values ('192. 168.0.1 ', 1 );
}";
Mysql tutorial _ query ($ SQL );
For more details, see: http://www.111cn.net/database/mysql/33922.htm

 

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.