exists

sql 判断 函数 存储过程是否存在的方法

喜欢而已 提交于 2019-11-29 12:11:49
下面为您介绍sql下用了判断各种资源是否存在的代码,需要的朋友可以参考下,希望对您学习sql的函数及数据库能够有所帮助。 库是否存在 if exists(select * from master..sysdatabases where name=N'库名') print 'exists' else print 'not exists' --------------- -- 判断要创建的表名是否存在 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -- 删除表 drop table [dbo].[表名] GO --------------- --判断要创建临时表是否存在 If Object_Id('Tempdb.dbo.#Test') Is Not Null Begin print '存在' End Else Begin print '不存在' End --------------- -- 判断要创建的存储过程名是否存在 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[存储过程名]') and

SQL语句判断表 数据库 数据是否存在

一个人想着一个人 提交于 2019-11-29 12:11:38
Sql Server中判断表或者数据库是否存在 if exists(select 1 from master..dbo.sysdatabases where name='example') print 'DataBase existed' else print 'Database not existed' 2.表 IF Exists(Select 1 From sysObjects Where Name ='表名' And Type In ('S','U')) Print 'Exists Table' Else Print 'Not Exists Table' Sql Server中判断表或者数据库是否存在 分类:软件开发2007.8.12 14:31 作者:stone | 评论:1 | 阅读:2996 1.数据库 if exists(select 1 from master..sysdatabases where name='example') print 'DataBase existed' else print 'Database not existed' 2.表 IF Exists(Select 1 From sysObjects Where Name ='表名' And Type In ('S','U')) Print 'Exists Table' Else Print

MySql - Create Table If Not Exists Else Truncate?

穿精又带淫゛_ 提交于 2019-11-29 11:06:22
问题 Here is the updated question: the current query is doing something like: $sql1 = "TRUNCATE TABLE fubar"; $sql2 = "CREATE TEMPORARY TABLE IF NOT EXISTS fubar SELECT id, name FROM barfu"; The first time the method containing this is run, it generates an error message on the truncate since the table doesn't exist yet. Is my only option to do the CREATE TABLE , run the TRUNCATE TABLE , and then fill the table? (3 separate queries) original question was: I've been having a hard time trying to

Delete files from directory if filename contains a certain word

痴心易碎 提交于 2019-11-29 11:05:13
问题 I need to check a directory to see if there are any files whose file name contains a specific keyword and if there are, to delete them. Is this possible? For example, delete all existing files in " C:\Folder " whose file name contains the keyword "Apple". 回答1: To expand on Henk's answer, you need: string rootFolderPath = @"C:\\SomeFolder\\AnotherFolder\\FolderCOntainingThingsToDelete"; string filesToDelete = @"*DeleteMe*.doc"; // Only delete DOC files containing "DeleteMe" in their filenames

IN与OR与EXISTS

北慕城南 提交于 2019-11-29 10:24:06
IN与OR与EXISTS 使用IN的子查询 : SELECT * FROM t1 WHERE x IN (SELECT y FROM t2); -- 等价于 SELECT * FROM t1, (SELECT DISTINCT y FROM t2) t WHERE t1.x= t.y; 可见,先t2表进行了全表的扫描并唯一排序,再根据t2的y列的值去索引匹配x列的值; 使用EXISTS的子查询 : SELECT * FROM t1 WHERE EXISTS (SELECT 1 FROM t2 WHERE y = t1.x); -- 等价于 FOR tab1 IN (SELECT x FROM t1) LOOP IF(EXISTS SELECT y FROM t2 WHERE y = tab1.x) THEN OUTPUT THE RECORD; END IF; END LOOP; 可见,先t1表全表检索,再通过索引 IN 和OR 的效率,在有索引的情况下,没有区别;没有索引时,IN 的效率要高于OR;OR的效率为O(n),而IN的效率为O(log n) 子查询,小表驱动大表,内层表小用IN,表大用EXISTS;NOT EXISTS 无论什么情况都要大于NOT IN; 来源: https://www.cnblogs.com/f1ynn/p/11515255.html

PHP上传文件仿微信文件名命名

核能气质少年 提交于 2019-11-29 09:44:34
在做文件上传时遇到一个需求,上传时判断文件名称是否重复,如果重复则在后面标记数字,重新命名后继续上传。 比如文件名为“测试.jpg”,上传时假如该文件存在,则改名为“测试(1).jpg”上传。 下面为代码展示 效果图 public function uploadFile(Request $request) { // $data = json_decode(file_get_contents("php://input"), true); $userId = request()->userid; if (!$userId) return $this->responseJson(self::CODE_USER_NOT_EXIST, trans('api.user.notExist')); $file = $request->file('file'); Log::channel('notify')->info($file); //获取文件名 $fileName = $file->getClientOriginalName(); $fileSize = $file->getClientSize(); $fileType = $file->guessClientExtension(); $path = 'upload\\' . $userId . '\\'; //判断文件是否存在

Exists / not exists: 'select 1' vs 'select field'

Deadly 提交于 2019-11-29 09:15:50
Which one of the two would perform better(I was recently accused of not being careful with my code because I used the later in Oracle): Select * from Tab1 Where (not) exists(Select 1 From Tab2 Where Tab1.id = Tab2.id) Select * from Tab1 Where (not) exists(Select Field1 From Tab2 Where Tab1.id = Tab2.id) Or are they both same? Please answer both from SQL Server perspective as well as Oracle perspective. I have googled (mostly from sql-server side) and found that there is still a lot of debate over this although my present opinion/assumption is the optimiser in both the RDMBS are mature enough

day07-多表查询

人走茶凉 提交于 2019-11-29 09:09:37
本节重点: 多表连接查询 符合条件连接查询 子查询 准备工作:准备两张表,部门表(department)、员工表(employee) create table department( id int, name varchar(20) ); create table employee( id int primary key auto_increment, name varchar(20), sex enum('male','female') not null default 'male', age int, dep_id int ); #插入数据 insert into department values (200,'技术'), (201,'人力资源'), (202,'销售'), (203,'运营'); insert into employee(name,sex,age,dep_id) values ('tom','male',18,200), ('mike','female',48,201), ('jack','male',38,201), ('lucy','female',28,202), ('lili','male',18,200), ('alice','female',18,204) ; # 查看表结构和数据 mysql> desc department; +-------+

python之路_mysql数据操作2

故事扮演 提交于 2019-11-29 09:09:08
一、多表连接查询   按照如下命令创建department,employee两个表格: #创建表 create table department( id int, name varchar(20) ); create table employee( id int primary key auto_increment, name varchar(20), sex enum('male','female') not null default 'male', age int, dep_id int ); #插入数据 insert into department values (200,'技术'), (201,'人力资源'), (202,'销售'), (203,'运营'); insert into employee(name,sex,age,dep_id) values ('egon','male',18,200), ('alex','female',48,201), ('wupeiqi','male',38,201), ('yuanhao','female',28,202), ('liwenzhou','male',18,200), ('jingliyang','female',18,204) ; #重点:外链接语法 SELECT 字段列表 FROM 表1 INNER|LEFT

Check if twitter username exists

落花浮王杯 提交于 2019-11-29 08:20:08
问题 Is there a way to check if a twitter username exists? Without being authenticated with OAuth or the twitter basic authentication? 回答1: According to the api docs you can pass an email address to the user/ show method, I would assume that if a user didn't exist you'd get back a 404, which should allow you to determine whether or not the user exists. eg: http://twitter.com/users/show.xml?email=t...@example.com result if not exist : <?xml version="1.0" encoding="UTF-8"?> <hash> <request>/users