1. Determine whether a data table exists
Method 1:
Use yourdb;Go
If object_id (N 'tablename', N 'U') is not nullPrint 'exist'ElsePrint 'nonexistent'
For example:Use fireweb;Go
If object_id (n'temp _ TBL ', n'u') is not nullPrint 'exist'ElsePrint 'nonexistent'
Method 2:
USE [Instance name]GO
If exists (SELECT * FROM dbo. SysObjects where id = object_id (n' [
Tags: style blog http color using file Data 2014Create a temporary table, #代表局部临时表, # #代表全局临时表. What is the specific meaning of local temporal tables and global temporary tables?For example, it is clearer to look at the local temporary table, "New query", enter the following text:After running, we execute input in this file: SELECT * from #tempTable, after execution can query the following data:We also open
Session
We sometimes encounter such a problem, at a certain time there is always a large query caused the temporary table space error. But we can't wait to catch the relevant SQL to optimize or process. Can be diagnosed through events.
Sys@ocn>alter Session SET EVENTS2 ' 1652 trace name errorstack level 1 ';Session altered.Sys@ocn>select Count (*) from (SELECT * to Alibaba.member order by Member_level);Sele
Label:Select field 1, Field 2, Field 3 into Tempname form table where table.id=1;This will give the Tempname table an auto-generated field 1, Field 2, field 33 fields, and values.Modify table field values, according to NidUpdate tablename SET field 1=TB.SSM from (select field as SSM from Table2) TBwhere Tbalename.nid=tb.nidAdd a field to a tableALTER
Update company set Tfn=null where tfn= '-2147483648 'Update application set Companytfn=null where companytfn=-2147483648UPDATE Company set Tfn=null where CAST (TFN as int) UPDATE Application Set Companytfn=null WHERE companytfnSelect object_id from sys.columns where name like '%hin% 'SELECT * from Sys.tables where object_id in (select object_id from sys.columns where name like '%hin% ')/////////////////////////////////////////////////////////////////////////////////////////////////drop
SQL server to determine whether a table or temporary table exists, SQL server
1. Determine whether a data table exists
Method 1:
Use yourdb; goif object_id (N 'tablename', N 'U') is not
Label:Recently made a report in which stored procedures, cursors, CTE expressions, temporal tables, and table variables are used in the report. The problem comes when the cursor iterates through the data in the CTE, stores the corresponding data in the variable, inserts the variable into the table variable, and after the cursor ends, wants to filter the table var
SQL Server checks whether a temporary table exists
if object_id('tempdb..##TEMPTABLE1') is not null drop table ##TEMPTABLE1
The above type is not checked. # temptable1 may be the name of view or procedure,
The complete check is as follows:
if
Want to use kettle to achieve a very simple requirement, from MySQL to Oracle import a table data, if the table in Oracle does not exist, first table and then import data. This is a seemingly simple feature, but it may be a bit confusing for users who have just started to touch kettle. There is a "check
1. If the table does not have an auto-growing identity column (int) using the temp tableSELECT IDENTITY (int) NewID,.. Into #tmp from youtable2. Tables with identity columns using table variablesINSERT into @tmpTableSELECT ..., NewID= (SELECT COUNT (*) from youtable b WHERE b.aidWhen you have a continuous newid from 1 to ~d, you can use loops to manipulate each r
SQL parse string added to temporary table SQL stored procedure in parameter input workaroundAdding string parsing to a staging tableSELECT * into #临时表 from dbo. Func_splitonecolumntabel (' 001,gf ', ', ')SELECT * FROM table where ID in (SELECT ID from temp
Placeholder first, edit later
There are four ways to judge:
1. Show tables like 'testtable ';
This method is not easy to implement in the code.2. SelectTABLE_NAMEFromINFORMATION_SCHEMA.TABLESWhereTABLE_SCHEMA= 'Dbname'AndTABLE_NAME= 'Tablename';
This method is easy to implement. An instance that determines whether the testtable table exists in mybase:
MySQL; mysql_res * result = NULL; int COUNT = 0; If (0 =
Directly on the code////////////$find _table the name of the table to find//$database a database handle that has been connected function check_table_is_exist($find _table,$database){ $sqlExce="Show Tables";//To show Databases $row= mysql_query ($sqlExce,$database); while($result= Mysql_fetch_array ($row, Mysql_num)) { for($i=0;$i$result);$i++){if($find _table==$result[$i]) {//echo "found". $find _table. ' return true; } }
Use the user_indexes and user_ind_columns system tables to view existing indexes. For existing indexes in the system, we can use the following two system views (user_inde
Use the user_indexes and user_ind_columns system tables to view existing indexes. For existing indexes in the system, we can use the following two system views (user_inde
Use the user_indexes and user_ind_columns system tables to view existing indexes.
For existing indexes in the system, we can use the following two system
* from sys.views WHERE object_id = ' [dbo].[ View name] ')6 determining if a function has SQL code--Determine if the name of the function to be created existsif exists (SELECT * from dbo.sysobjects WHERE id = object_id (' [dbo].[ Function name] ') and xtype in (' FN ', ' IF ', ' TF ')Wk_ad_begin ({pid:21}); Wk_ad_after (, function () {$ ('. Ad-hidden '). Hide ();}, function () {$ ('. Ad-hidden '). Show ();
Use the user_indexes and user_ind_columns system tables to view existing indexes.
For existing indexes in the system, we can use the following two system views (user_indexes and user_ind_columns) to view the specific content, for example, which table belongs to, which column and, specific parameters.
User_indexes: The System View stores the index name and whether the index is a unique index.
User_ind_column: The System View stores the index name, corr
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.