Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : sql

Java Ö´ÐÐ SQL ½Å±¾Îļþ

ÊÇ¿½±´µÄ±ðÈ˵ģ¬ÒÔ±¸Ñ§Ï°
package com.unmi.db;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ¶ÁÈ¡ SQL ½Å±¾²¢Ö´ÐÐ
* @author Unmi
*/
public class SqlFileExecutor {
/**
* ¶ÁÈ¡ SQL Îļþ£¬»ñÈ¡ SQL Óï¾ä
* @param sqlFile SQL ½Å±¾Îļþ
* @return List<sql> ·µ»ØËùÓÐ SQL Óï¾äµÄ List
* @throws Exception
*/
private List<String> loadSql(String sqlFile) throws Exception {
List<String> sqlList = new ArrayList<String>();
try {
InputStream sqlFileIn = new FileInputStream(sqlFile);
StringBuffer sqlSb = new StringBuffer();
byte[] buff = new byte[1024];
int byteRead = 0;
while ((byteRead = sqlFileIn.read(buff)) != -1) {
sqlSb.append(new String(buff, 0, byteRead));
}
// Windows Ï»»ÐÐÊÇ \r\n, Linux ÏÂÊÇ \n
String[] sqlArr = sqlSb.toString().split("(;\\s*\\r\\n) ......

Java Ö´ÐÐ SQL ½Å±¾Îļþ

ÊÇ¿½±´µÄ±ðÈ˵ģ¬ÒÔ±¸Ñ§Ï°
package com.unmi.db;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* ¶ÁÈ¡ SQL ½Å±¾²¢Ö´ÐÐ
* @author Unmi
*/
public class SqlFileExecutor {
/**
* ¶ÁÈ¡ SQL Îļþ£¬»ñÈ¡ SQL Óï¾ä
* @param sqlFile SQL ½Å±¾Îļþ
* @return List<sql> ·µ»ØËùÓÐ SQL Óï¾äµÄ List
* @throws Exception
*/
private List<String> loadSql(String sqlFile) throws Exception {
List<String> sqlList = new ArrayList<String>();
try {
InputStream sqlFileIn = new FileInputStream(sqlFile);
StringBuffer sqlSb = new StringBuffer();
byte[] buff = new byte[1024];
int byteRead = 0;
while ((byteRead = sqlFileIn.read(buff)) != -1) {
sqlSb.append(new String(buff, 0, byteRead));
}
// Windows Ï»»ÐÐÊÇ \r\n, Linux ÏÂÊÇ \n
String[] sqlArr = sqlSb.toString().split("(;\\s*\\r\\n) ......

¾¡Á¿±ÜÃâÔÚSQLÓï¾äÖÐʹÓÃLIKE

----start
    Ç°Ã棬ÎÒÃǽéÉÜÁË ¾¡Á¿±ÜÃâÔÚSQLÓï¾äµÄWHERE×Ó¾äÖÐʹÓú¯Êý£¬ÒòΪÕâÑù×ö»áʹ¸Ã×Ö¶ÎÉϵÄË÷ÒýʧЧ£¬Ó°ÏìSQLÓï¾äµÄÐÔÄÜ¡£»ùÓÚͬÑùµÄµÀÀí£¬ÎÒÃÇÒ²Ó¦¸Ã±ÜÃâʹÓÃLIKE¡£¿¼ÂÇÏÂÃæµÄÇé¿ö£º
CREATE TABLE USER
(
NAME VARCHAR(20) NOT NULL,---ÐÕÃû
MYNUMBER VARCHAR(18)---Éí·ÝÖ¤ºÅÂë
); 
ÏÖÔÚÒªÇóÄã°ÑÉí·ÝÖ¤ºÅÂ뿪ͷÊÇ2102£¨´óÁ¬ÈË£©²é³öÀ´£¬Ôõô°ì£¿ÎÒÃǺÜ×ÔÈ»µÄ»áÕâôд£º
SELECT * from USER WHERE MYNUMBER LIKE '2102%'; 
ÉÏÊöÓï¾äÍêÈ«ÕýÈ·£¬Ö»¿ÉϧÐÔÄܲ»ºÃ£¬ÄÇôµ½µ×ÈçºÎ´¦ÀíÄØ£¿´ð°¸Êǽ«Ëüת»¯Îª·¶Î§É¨Ã裬ÈçÏ£º
SELECT * from USER WHERE MYNUMBER>='210200000000000000' AND MYNUMBER<'210300000000000000'; 
---¸ü¶à²Î¼û£ºDB2 SQL ¾«Òª
----ÉùÃ÷£º×ªÔØÇë×¢Ã÷³ö´¦¡£
----last update at 2009.9.24
----write by wave at 2009.9.24
----end ......

SQL SERVERµ¼ÈëBAKÎļþ

ϵͳ»·¾³£ºwindows xp pro
Êý¾Ý¿â£ºMS Sql 2000
IIS: 5.1 ASP.NET2.0
ÒòΪ´úÂëÊÇ2.0.netµÄ,ûÓа취ֻºÃ°²×°ÁË.netÏÂÔØÄã¿ÉÒÔȥ΢ÈíµÄÍøÕ¾ÉÏÈ¥ÏÂÔØ.Õâ¸öÊÇÃâ·ÑµÄÈí¼þ£¬ÎÒÖªµÀµÄÊÇÃâ·ÑµÄ¡£
Êý¾Ý¿â×öÁËѹËõºó׺ÊÇbakµÄ£¬ËùÒÔÊý¾Ý¿â²»ÄÜÖ±½ÓʹÓã¬ÐèÒªµ¼ÈëÔÚÍøÉϲéÁ˺ܶàµÄ×ÊÁϵ«ÊDz»¶à£¬µ«×Ô¼º³É¹¦µ¼ÈëÁË£¬Ð´ÏÂÀ´×öÒ»¸ö±¸ÍüÒÔÃâÒÔºóÓÖÍü¼ÇÁË¡£
Ê×ÏÈ´ò¿ªSQLµÄÆóÒµ¹ÜÀí¹¤¾ß£¬´ò¿ªÊý¾Ý¿âÏî¿ÉÒÔ¿´µ½×ó²àÓкܶàµÄÊý¾Ý¿â£¬ÄǸöϵͳ×Ô´øµÄ²»Òª¶¯£¬ÔÚÓÒ²à¿Õ°×´¦µãÓÒ¼üÑ¡“ËùÓÐÈÎÎñ”“»¹Ô­Êý¾Ý¿â”ÔÚ“»¹Ô­”ºóÓÐÈý¸öÑ¡ÏîÒÀ´ÎÊÇ“Êý¾Ý¿â”“Îļþ×é»òÎļþ”“´ÓÉ豸”Ñ¡Ôñ“´ÓÉ豸”ÔÚ“²ÎÊý”Ñ¡ÔñÒ»¸öÉ豸£¬Õâ¸öÆäʵ¾ÍÊÇÄã´æ·ÅBAKÎļþµÄ´ÅÅÌ£»ÁíÒ»¸öÎÊÌâ¾ÍÊÇÑ¡Ôñ“Ñ¡Ïî”Ñ¡Ôñ“ÔÚÏÖÓÐÊý¾Ý¿âÉÏÇ¿ÖÆ»¹Ô­”È»ºó´òµ½ÄãÒª»¹Ô­µÄBAKÊý¾Ý¿âÑ¡»¹Ô­¾Í¿ÉÒÔÁË¡£
ÔÚ»¹Ô­µÄ¹ý³ÌÖÐÓöµ½Ò»¸ö´íÎóµÄÌáʾ´óÌåÒâ˼ÊÇ˵É豸´íÎó»òËð»µÎÞ·¨»¹Ô­Ö¸¶¨µÄÊý¾Ý¿â£¬¿ªÊ¼µÄʱºò×Ô¼ºÒÔΪÊÇSQLÓÐÎÊÌâµÄ£¬ºóÀ´×Ðϸ¿´ÁËһϷ¾¶£¬Ô­À´ÊÇĬÈϵÄ·¾¶²»´æÔÚÔì³É´íÎóµÄÌáʾ£¬ÒòΪ×Ô¼ºÔÚ°²×°SQLµÄʱºò°ÑĬÈÏ´æ·ÅÊ ......

SqlServer ²éѯsqlÖ´ÐÐʱ¼ä

ÔÚ²éѯ·ÖÎöÆ÷ÖÐÊäÈëÒÔÏÂÄÚÈÝ£º
set statistics profile on
set statistics io on
set statistics time on
go

go
set statistics profile off
set statistics io off
set statistics time off ......

SqlServer ²éѯsqlÖ´ÐÐʱ¼ä

ÔÚ²éѯ·ÖÎöÆ÷ÖÐÊäÈëÒÔÏÂÄÚÈÝ£º
set statistics profile on
set statistics io on
set statistics time on
go

go
set statistics profile off
set statistics io off
set statistics time off ......

SQL SERVERʹÓÃÊÂÎñÈÕÖ¾»Ö¸´Êý¾ÝµÄʵÑé

/*
ʹÓÃÊÂÎñÈÕÖ¾»Ö¸´Êý¾ÝµÄʵÑé
*/
--1.´´½¨²âÊÔÊý¾Ý¿â
CREATE DATABASE Db_test
ON
( NAME = Db_test_DATA,
      FILENAME = 'c:\Db_test.mdf' )
LOG ON
( NAME = Db_test_LOG,
   FILENAME = 'c:\Db_test.ldf')
GO
--2.¹ÊÕÏ»¹Ô­Ä£ÐÍÉèÖÃΪfullÄ£ÐÍ,ĬÈϵļòµ¥Ä£Ðͱ¸·ÝÊÂÎñÈÕÖ¾ÊÇûÓõÄ
ALTER   DATABASE   Db_test   SET   RECOVERY   FULL   |   BULK_LOGGED
--3.´´½¨²âÊÔ±í
CREATE TABLE [dbo].[BackupTabToTxt] (
 [TabName] [varchar] (200)  ,
)
--4.²åÈë²âÊÔÊý¾Ý
insert into BackupTabToTxt(TabName) values('test1')
insert into BackupTabToTxt(TabName) values('test2')
insert into BackupTabToTxt(TabName) values('test3')
select * from BackupTabToTxt
--5.±¸·ÝÊý¾Ý¿â
BACKUP DATABASE Db_test TO DISK='c:\test_data.bak'
--6.ɾ³ýÊý¾Ý,±¸·ÝÈÕÖ¾
delete from BackupTabToTxt where TabName='test3'  --17:06
BACKUP LOG Db_test TO DISK='c:\test_log_1706.bak' --±¸·ÝÈÕÖ¾
delete from Backu ......

mysqlµÄ´óÅúÁ¿µ¼ÈëÊý¾ÝsqlÓï¾äµÄÒ»µãÓÅ»¯

´óÅúÁ¿²åÈëÊý¾Ýʱ 1,myisam±í,¿ÉÒÔÏÈͨ¹ý alter table table_name disable keys;#ÏȹرձíµÄË÷Òý¼ì²é,×¢ÒâÊÇ·ÇΨһË÷Òý! load data infile ¡®/path/file¡¯ into table table_name; alter table table_name anable keys;#ÔÙ´ò¿ªË÷Òý ¿É´ó´ó¼Ó¿ìµ¼Èë.»¹ÓпÉÒÔÉèÖÃbulk_insert_buffer_sizeÖµÀ´Ìá¸ß²åÈëËÙ¶È 2,innodb±í,ÉÏÃæ·½·¨²»Ôõô´ÕЧ ¿ÉÒÔ¶ÔÊý¾Ý°´Ö÷¼ü½øÐÐÅÅÐò,ÒòΪinnodbÊÇ°´Ö÷¼ü˳Ðò±£´æÊý¾ÝµÄ;ÔÚµ¼ÈëÊý¾Ý֮ǰ¿ÉÒÔÏȹرÕΨһË÷ÒýЧÑé set unique_checks=0; Èç¹ûÓÐ×Ô¶¯Ìá½»,ÏÈ¹Ø±Õ set autocommit=0; ......

mysqlµÄ´óÅúÁ¿µ¼ÈëÊý¾ÝsqlÓï¾äµÄÒ»µãÓÅ»¯

´óÅúÁ¿²åÈëÊý¾Ýʱ 1,myisam±í,¿ÉÒÔÏÈͨ¹ý alter table table_name disable keys;#ÏȹرձíµÄË÷Òý¼ì²é,×¢ÒâÊÇ·ÇΨһË÷Òý! load data infile ¡®/path/file¡¯ into table table_name; alter table table_name anable keys;#ÔÙ´ò¿ªË÷Òý ¿É´ó´ó¼Ó¿ìµ¼Èë.»¹ÓпÉÒÔÉèÖÃbulk_insert_buffer_sizeÖµÀ´Ìá¸ß²åÈëËÙ¶È 2,innodb±í,ÉÏÃæ·½·¨²»Ôõô´ÕЧ ¿ÉÒÔ¶ÔÊý¾Ý°´Ö÷¼ü½øÐÐÅÅÐò,ÒòΪinnodbÊÇ°´Ö÷¼ü˳Ðò±£´æÊý¾ÝµÄ;ÔÚµ¼ÈëÊý¾Ý֮ǰ¿ÉÒÔÏȹرÕΨһË÷ÒýЧÑé set unique_checks=0; Èç¹ûÓÐ×Ô¶¯Ìá½»,ÏÈ¹Ø±Õ set autocommit=0; ......
×ܼǼÊý:4346; ×ÜÒ³Êý:725; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [701] [702] [703] [704] 705 [706] [707] [708] [709] [710]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ