Mysql SQL statement comments and mysqlsql statement comments

Source: Internet
Author: User

Mysql SQL statement comments and mysqlsql statement comments

Annotations can be added to MySQL SQL statements. The following describes the description of mysql SQL statements. Let's take a look!

1, Note: create database create database database-name2, Note: delete DATABASE drop database dbname3, note: Backup SQL server --- CREATE backup data deviceUSE masterEXEC sp_addumpdevice 'disk', 'testback ', 'C: \ mssql7backup \ MyNwind_1.dat '--- start to back up BACKUPDATABASE pubsTO testBack4. Note: create table tabname (col1 type1 [not null] [primary key], col2 type2 [not null],...) create A new table based on an existing table: A: create table tab_newlike tab_old (create A new table using the old table) B: create table tab_newas select Col1, col2... From tab_old definition only5. Description: Delete the new table drop table tabname6. Description: add an Alter table tabnameadd column col type. Note: The column cannot be deleted after it is added. After columns are added to DB2, the data type cannot be changed. The only change is to increase the length of the varchar type. 7. Description: Add a primary key: Alter table tabnameadd primary key (col) Description: delete a primary key: Alter table tabnamedrop primary key (col) 8. Description: Create an index: create [unique] index idxnameon tabname (col ....) Delete index: drop index idxname Note: The index cannot be changed. To change the index, you must delete it and recreate it. 9. Description: create view viewnameas select statement Delete view: drop view viewname10. Description: select a few simple basic SQL statements: select * from table1where: insert into table1 (field1, field2) values (value1, value2) delete: delete from table1where range update table1set field1 = value1where range search: select * from table1where field1like '% value1 %' --- the like syntax is very subtle, query information! Sort: select * from table1order by field1, field2 [desc] Total: select count as totalcountfrom table1 sum: select sum (field1) as sumvaluefrom table1 average: select avg (field1) as avgvaluefrom table1 max: select max (field1) as maxvaluefrom table1 min: select min (field1) as minvaluefrom table111 Note: several advanced query computation terms: the UNION operator combines two other result tables (such as TABLE1 and TABLE2) and removes any duplicate rows from the table to generate a result table. When ALL is used together with UNION (that is, union all), duplicate rows are not eliminated. In either case, each row of the derived table is from either TABLE1 or table2. B: The distinct t operator. The distinct t operator derives a result table by including all rows in Table 1 but not in table 2 and eliminating all repeated rows. When ALL is used with distinct T (distinct t all), duplicate rows are not eliminated. C: INTERSECT operator the INTERSECT operator derives a result table by only including rows in TABLE1 and TABLE2 and eliminating all repeated rows. When ALL is used with INTERSECT (intersect all), duplicate rows are not eliminated. Note: The query results of several computation words must be consistent. 12. Note: Use outer join A and left (outer) join: left outer join (left join): the result set contains matching rows of the connected table, and all rows of the left join table. SQL: select. a,. b,. c, B. c, B. d, B. f from aLEFT out join bON. a = B. cB: right (outer) join: right outer join (right join): the result set includes both matched join rows in the connection table and all rows in the right join table. C: full/cross (outer) join: full outer join: includes not only matching rows in the symbolic join table, but also all records in the two connection tables. 12. Group: Group by: A table. After grouping is completed, you can only obtain Group-related information. Group-related information: (Statistical Information) criteria for grouping count, sum, max, min, and avg) in SQLServer: text, ntext, fields of the image type can be grouped based on fields in the selecte statistics function. They cannot be put together with common fields. 13. perform operations on the database: detaching the database: sp_detach_db; and attach the database: sp_attach_db indicates that the complete path 14 is required for appending. how to modify the Database name: sp_renamedb 'old _ name', 'new _ name' 2. Upgrade 1. Description: copy the table (only copy the structure, source table name: a new table name: b) (Access available) Method 1: select * into bfrom awhere 1 <> 1 (for SQlServer only) Method 2: select top 0 * into bfrom a2, description: copy table (copy data, source table name: a target table name: B) (Access available) insert B (a, B, c) select d, e, ffrom B; 3. Description: copy a table across databases (the absolute path is used for specific data) (Access is available) insert into B (a, B, c) select d, e, ffrom bin 'specific database' where condition example :.. from bin' "& Server. mapPath (". ") &" \ data. mdb "&" 'where .. 4. Description: subquery (table name 1: a table name 2: B) select a, B, cfrom awhere aIN (select dfrom B) or: select a, B, cfrom awhere aIN (, 3) 5. Note: select. title,. username, B. adddatefrom table a, (select max (adddate) adddate from tabl E where table. title =. title) b6, Description: External join query (table name 1: a table name 2: B) select. a,. b,. c, B. c, B. d, B. f from aLEFT out join bON. a = B. c7, Description: Online View query (table name 1: a) select * from (SELECT a, B, cFROM a) T where t. a> 1; 8. Description: between usage. When between restricts the Data Query range, it includes the boundary value. not between does not include select * from table1where time between time1and time2select a, B, c, from table1where anot between value 1and value 29. Description: in usage method select * from table1where a [not] in ('value 1', 'value 2', 'value 4', 'value 6') 10. Description: two joined tables, delete information that has not been found in the secondary table in the primary table: delete from table1where not exists (select * from table2where table1.field1 = table2.field1) 11. Description: Table 4 Joint query problem: select * from aleft inner join bon. a = B. bright inner join con. a = c. cinner join don. a = d. dwhere ..... 12. Note: Five minutes ahead of schedule reminder SQL: select * from Schedule where datediff ('minute ', f Start Time, getdate ()> 513. Description: select top 10 B in a single SQL statement. * from (select top 20 primary key field, sorting Field From table name order by sorting field desc) a, table name B where B. primary key field =. primary key field order by. specific implementation of sorting fields: Database paging: declare @ startint, @ end int @ SQL nvarchar (600) set @ SQL = 'select top '+ str (@ end-@ start + 1) +' + from Twhere ridnot in (select top '+ str (@ str-1) + 'ridfrom Twhere Rid>-1) 'exec sp_executesql @ SQL Note: a variable cannot be directly followed after top, so this is the only special method in actual application. Rid is an identifier column. If there are specific fields after top, this is very beneficial. This avoids the inconsistency in the actual table after the query results of the top field if it is a logical index. (the data in the logical index may be inconsistent with that in the data table, if the query is indexed, the index is first queried.) 14. Note: select top 10 * form table1 where range of the first 10 records 15. Description: select all the information of the largest a record corresponding to the data with the same B value in each group (usage similar to this can be used for monthly ranking of the forum and Analysis of popular products each month, rank by subject score, etc .) select a, B, cfrom tablename ta where a = (select max (a) from tablename tb where tb. B = ta. b) 16. Description: includes all rows in TableA but not in TableB and TableC and removes all repeated rows to derive a result table (select afrom tableA) using t (select afrom tableB) except (Select afrom tableC) 17. Description: select top 10 * from tablenameorder by newid () 18. Description: select newid () 19. Description: delete record 1), delete from tablenamewhere idnot in (select max (id) from tablenamegroup by col1, col2 ,...) 2), select distinct * into temp from tablename delete from tablename insert into tablenameselect * from temp comment: this operation involves moving a large amount of data, this method is not suitable for large capacity but data operation 3). For example, to import data into an external table, for some reason, only a part is imported for the first time, but it is difficult to determine the specific location. In the next import, multiple duplicate fields are generated. How to delete the duplicate field alter table tablename -- add an auto-incrementing column add column_bint identity) delete from tablenamewhere column_bnot in (select max (column_ B) from tablenamegroup by column1, column2 ,...) alter table tablenameddrop column column_b20: list all the table names in the database. select name from sysobjectswhere type = 'U' // U indicates user 21. Description: list all columns in the Table. select name from syscolumnswhere id = object_id ('tablename') 22. Description: List type, vender, p The cs field is arranged by the type field. case can be easily selected, similar to case in select. Select type, sum (case venderwhen 'a then pcselse 0end), sum (case venderwhen 'C' then pcselse 0end), sum (case venderwhen 'B' then pcselse 0end) FROM tablenamegroup by type: type vender pcs computer A 1 computer A 1 Disc B 2 Disc A 2 mobile phone B 3 mobile phone C 323, Description: initialization TABLE table1TRUNCATE TABLE table124, description: select top 5 * from (select top 15 * from table order by idasc) records from 10 to 15) table _ alias order by iddesc 3. Tips 1, 1 = 2, use more "where 1 = 1 "indicates Selecting All" where 1 = 2 "and not Selecting All, for example: if @ strWhere! = ''Ininset @ strSQL = 'select count (*) as Total from ['+ @ tblName +'] where' + @ strWhereendelsebeginset @ strSQL = 'select count (*) as Total from ['+ @ tblName +'] 'end we can directly write an error! Directory item not found. Set @ strSQL = 'select count (*) as Total from ['+ @ tblName +'] where 1 = 1 stationary '+ @ strWhere 2. shrink the database -- re-create the index dbcc reindexdbcc indexdefrag -- contract data and log dbcc shrinkdbdbcc SHRINKFILE3 and compress database dbcc shrinkdatabase (dbname) 4. Transfer the database to a new user with the existing user permission exec sp_change_users_login 'Update _ one', 'newname', 'oldname' go5. Check the backup set restore verifyonly from disk = 'e: \ dvbbs. bak '6. Fix database alter database [dvbbs] SET SINGLE_USERGODBCC CHECKDB ('dvbbs ', rep Air_allow_data_loss) with tablockgoalter database [dvbbs] SET MULTI_USERGO7, log clearing set nocountondeclare @ LogicalFileName sysname, @ MaxMinutesINT, @ NewSizeINTUSE tablename -- SELECT the name of the database to be operated @ LogicalFileName = 'tablename _ log', -- log file name @ MaxMinutes = 10, -- Limit on time allowed to wrap log. @ NewSize = 1 -- the size of the log file you want to set (M) Setup/initializeDECLARE @ OriginalSizeintSELECT @ OriginalSize = size FROM sysfiles WH ERE name = @ LogicalFileNameSELECT 'ininal Size of '+ db_name () + 'Log is' + CONVERT (VARCHAR (30), @ OriginalSize) + '8 K pages or '+ CONVERT (VARCHAR (30), (@ OriginalSize * 8/1024) + 'mb' FROM sysfiles WHERE name = @ LogicalFileNameCREATE TABLE DummyTrans (DummyColumnchar (8000) not null) DECLARE @ Counter INT, @ StartTime DATETIME, @ TruncLog VARCHAR (255) SELECT @ StartTime = GETDATE (), @ TruncLog = 'backu P log' + db_name () + 'WITH TRUNCATE_ONLY 'dbcc SHRINKFILE (@ LogicalFileName, @ NewSize) EXEC (@ TruncLog) -- Wrap the LOG if necessary. WHILE @ MaxMinutes> DATEDIFF (mi, @ StartTime, GETDATE () -- time has not expired AND @ OriginalSize = (SELECT size FROM sysfilesWHERE name = @ LogicalFileName) AND (@ OriginalSize * 8/1024)> @ NewSize BEGIN -- Outer loop. SELECT @ Counter = 0 WHILE (@ Counter <@ OriginalS Ize/16) AND (@ Counter <50000) BEGIN -- update INSERT DummyTransVALUES ('fill log') DELETE DummyTrans SELECT @ Counter = @ Counter + 1 end exec (@ TruncLog) ENDSELECT 'final Size of '+ db_name () + 'Log is' + CONVERT (VARCHAR (30), size) + '8 K pages or '+ CONVERT (VARCHAR (30 ), (size * 8/1024) + 'mb' FROM sysfiles WHERE name = @ logicalfilenameddrop TABLE DummyTransSET NOCOUNTOFF8. Note: change a TABLE exec sp_change Objectowner 'tablename', 'dbo' 9. Store and change all tables create procedure dbo. reply @ OldOwneras NVARCHAR (128), @ NewOwneras NVARCHAR (128) ASDECLARE @ Name as NVARCHAR (128) DECLARE @ Owner as NVARCHAR (128) DECLARE @ OwnerName as NVARCHAR (128) DECLARE curObjectCURSOR FORselect 'name' = Name, 'owner' = user_name (uid) from sysobjectswhere user_name (uid) = @ OldOwnerorder by nameOPEN curObjectFETCH next from curObj EctINTO @ Name, @ OwnerWHILE (@ FETCH_STATUS = 0) BEGIN if @ Owner = @ OldOwnerbegin set @ OwnerName = @ OldOwner + '. '+ rtrim (@ Name) exec sp_changeobjectowner @ OwnerName, @ NewOwnerend -- select @ name, @ NewOwner, @ OldOwnerFETCH next from curObjectINTO @ Name, @ OwnerENDclose curObjectdeallocate curObjectGO10. SQL server directly writes data cyclically. declare @ iintset @ I = 1 while @ I <30 begin insert into test (userid) values (@ I) set @ I = @ I + 1e Nd case: as shown in the following table, all the failures in the system are required to pass the test: name score Zhangshan 80 Lishi 59 Wangwu 50 Songquan 69 while (select min (score) from tb_table) <60) beginupdate tb_tableset score = score * 1.01 where score <60if (select min (score) from tb_table)> 60 break else continueend data development-classic 1. sort By surname strokes: Select * From TableNameOrder By CustomerNameCollate Chinese_PRC_Stroke_ci_as // From less to more 2. database encryption: select encrypt ('original password') select pwden Crypt ('original password') select pwdcompare ('original password', 'encrypted password') = 1 -- same; otherwise, different encrypt ('original password ') select pwdencrypt ('original password') select pwdcompare ('original password', 'encrypted password') = 1 -- same; otherwise not the same 3. retrieve the table fields: declare @ listvarchar (1000), @ SQL nvarchar (1000) select @ list = @ list + ',' + B. name from sysobjects a, syscolumns B where. id = B. idand. name = 'table a' set @ SQL = 'select' + right (@ list, len (@ list)-1) + 'from table a' exec (@ SQL) 4. view the hard disk partition: EXEC master .. xp_fixeddrives5. comparison Whether tables A and B are equal: if (select checksum_agg (binary_checksum (*) from A) = (select checksum_agg (binary_checksum (*) from B) print 'equal to 'elasticprint' not equal to '6. kill all event Inspector processes: DECLARE hcforeachCURSOR global for select 'Kill '+ RTRIM (spid) FROM master. dbo. sysprocessesWHERE program_nameIN ('SQL filer', n' SQL event profiler') EXEC sp_msforeach_worker '? '7. record Search: Select Top N * From Table --------------------------------------- N to M records (primary index ID required) select Top M-N * From table Where IDin (Select Top m id From Table) Order by ID Desc ------------------------------------ N to the end record Select Top N * From Table Order by IDDesc Case Example 1: A table has more than 10 thousand records. The first RecID field of the table is an auto-increment field. Write an SQL statement to find the 31st to 40th records of the table. Select top 10 recid from Awhere recidnot in (select top 30 recid from A) Analysis: if this is the case, some problems may occur if the recid has A logical index in the table. Select top 10 recid from Awhere ...... Select top 30 recid from A is searched from the index, while select top 30 recid from A is searched in the data table. As A result, the order in the index may be different from that in the data table, in this way, the queried data is not originally expected. Solution 1: Use order by select top 30 recid from Aorder by ricid. If this field is not auto-incrementing, problem 2 will occur. In that subquery, add the following conditions: select top 30 recid from Awhere recid>-Example 2: query the last record in the table. You do not know how much data the table has and the table structure. Set @ s = 'select top 1 * from T where pid not in (select top '+ str (@ count-1) + 'pid from T) 'print @ s exec sp_executesql @ s9: Obtain the select Name from sysobjectswhere xtype = 'U' and status> = 010: obtain all the fields of a table. select name from syscolumnswhere id = object_id ('table name ') select name from syscolumnswhere idin (select idfrom sysobjectswhere type = 'U' and name = 'table name') two methods have the same effect 11: view the view, stored procedure, and function select a related to a table. * fr Om sysobjects a, syscomments B where. id = B. id and B. textlike '% table name %' 12: view all stored procedures in the current database select name as stored procedure name from sysobjectswhere xtype = 'P' 13: query all databases created by the user, select * from master .. sysdatabases D where sidnot in (select sidfrom master .. sysloginswhere name = 'sa ') or select dbid, name AS DB_NAMEfrom master .. sysdatabaseswhere sid <> 0x0114: queries the fields and Data Types of a table. select column_name, data_typefrom information_schema.columns Where table_name = 'table name' 15: Data operations between databases on different servers -- create a connection server exec sp_add+server 'itsv', '', 'sqlodb ', 'remote server name or IP address 'exec sp_addjavassrvlogin 'itsv', 'false', null, 'username ', 'Password' -- Query example select * from ITSV. database Name. dbo. table name -- import example select * into table from ITSV. database Name. dbo. table name -- delete the linked servers exec sp_dropserver 'itsv' and 'droplogins' when they are no longer in use -- connect to the remote/LAN data (openrowset/openquery/opendatasource) -- 1. openrowset -- Query example select * from openrowset ('sq Loledb', 'SQL Server name', 'username', 'Password', and database name. dbo. table Name) -- generate a local table select * into table from openrowset ('sqlodb', 'SQL Server name', 'username', 'Password', database name. dbo. table Name) -- import the local table into the remote table insert openrowset ('sqlodb', 'SQL Server name'; 'username'; 'Password', database name. dbo. table Name) select * from local table -- update local table update bset B. column A =. column A from openrowset ('sqlodb', 'SQL Server name'; 'username'; 'Password', database name. dbo. table Name) as ainner join local table bon. column1 = B. column1 -- create a connection for openquery usage -- first create a connection to create the connection server exec Sp_addrole server 'itsv', '', 'sqloledb', 'remote server name or IP address' -- Query select * FROM openquery (ITSV, 'select * FROM database. dbo. table name ') -- import the local table to the remote table insert openquery (ITSV, 'select * FROM database. dbo. table name ') select * from local table -- update local table update bset B. column B =. column BFROM openquery (ITSV, 'select * FROM database. dbo. table name ') as ainner join local table B on. column A = B. columns A--3, opendatasource/openrowsetSELECT * FROM opendatasource ('sqlodb', 'Data Source = ip/ServerN Ame; User ID = login name; Password = password '). test. dbo. roy_ta -- import the local table to the remote table insert opendatasource ('sqlodb', 'Data Source = ip/ServerName; User ID = login name; Password = password '). database. dbo. table Name select * from local table SQL Server basic functions 1. string function length and analysis use 1, datalength (Char_expr) to return the number of characters contained in the string, but does not contain the following space 2, substring (expression, start, length) to obtain the substring, the subscript of a string is from "1", start is the starting position, and length is the length of the string. In practice, len (expression) is used to obtain its length 3, right (char_expr, int_expr) returns the in at the right of the string. T_expr characters, left on the contrary 4, isnull (check_expression, replacement_value) If check_expression is empty, return the value of replacement_value. If not empty, return check_expression character operation class 5, sp_addtype custom numeric type: EXEC sp_addtype birthday, datetime, 'null' 6, set nocount {on | off} indicates that the returned results do not contain information about the number of rows affected by the Transact-SQL statement. If some statements contained in the stored procedure do not return much actual data, this setting greatly reduces network traffic and significantly improves performance. SETNOCOUNT is set during execution or runtime, rather than during analysis. When set nocount is ON, no count is returned (indicating the number of rows affected by the Transact-SQL statement ). When set nocount is OFF, return count common sense in the SQL query: the maximum number of tables or views that can be followed after from: 256 Order by appears in the SQL statement. When querying, sort first, in SQL, the maximum capacity of a field is 8000. For nvarchar (4000), nvarchar is a Unicode code. SQLServer2000 synchronous replication technology implementation step 1. Preparation 1. on the Publishing Server, the subscription server creates a windows user with the same name and sets the same password, as an effective access user for publishing snapshot folders-management tools-Computer Management-users and groups-right-click users-create a user (SynUser) that belongs to the administrator group to log on to windows 2. on the Publishing Server, create a new shared directory to store the released snapshot files. For details, click "My Computer -- D: \" to create a directory named: PUB -- Right-click the newly created directory -- properties -- share -- select "share this folder" -- use the "permission" button to set specific user permissions, make sure that the user (SynUser) created in step 1 has all permissions on the folder-OK 3. set the startup user (publish/subscribe server) of the SQL Server Agent service to start -- program -- management tool -- service -- Right-click SQLSERVERAGENT -- properties -- Login -- Select "this account" -- enter or select the windows logon User Name (SynUser) created in step 1 -- "password" and enter the password of this user. 4. set the SQL Server Authentication Mode to solve the permission issue during connection (this setting is done by the publishing/subscription servers) enterprise Manager -- Right-click SQL instance -- properties -- Security -- authentication -- select "SQL Server and Windows" -- OK 5. register the enterprise manager on the Publishing Server and subscription Server -- Right-click the SQL Server group -- create an SQL Server registration... -- next -- available server, enter the name of the remote server you want to register -- add -- next -- connection usage, select the second "SQL Server Authentication" -- next -- enter the user name and password (SynUser) -- next -- select the SQL Server group, or create a new group -- next -- finish 6. if you can only use IP addresses and cannot use computer names, register the server alias for them (this step is not used in implementation) (Configure on the connection end, For example, if the server name is configured on the subscription server, the IP address of the Publishing Server is entered) start -- program -- Microsoft SQL Server -- client network utility -- alias -- add -- network library select "TCP/IP" -- Server alias enter SQL Server name -- connection parameter -- enter Server name SQL Server IP Address -- If you modify the SQL port, unselect "dynamically determine port", and enter the corresponding port number 2. Formal configuration 1. Configure the Publishing Server to open the enterprise manager on the Publishing Server (B, C, D) perform the following steps: (1) select [configuration Publishing, subscription server and Distribution] from the [copy] sub-menu in the [tools] drop-down menu to display the configuration publishing and distribution wizard (2) [Next] You can select the distribution server as the distribution server or another SQL Server (select your own) (3) [Next] set the snapshot folder to use the Default \ servername \ Pub (4) [next] custom configuration options: Yes, let me set the attributes of the distribution database to enable the Publishing Service Or set the release settings, use the following default settings (recommended) (5) [next] set the distribution database name and location use the default value (6) [Next] enable the Publishing Server select as the Publishing Server (7) [next] select the database and publishing type to be published (8) [next] Select register subscription server (9) [Next] complete configuration 2. Create a publication publishing server B, C, and D (1) from the [copy] sub-menu in the [tools] menu, select [create and manage Publishing] command (2) Select the database for which you want to create a publication, and then click [Create Publishing] (3) in the prompt dialog box of the [Create release wizard], click [next]. A dialog box is displayed. The dialog box contains three types of copies. Now we select the first one, that is, the default snapshot release (the other two can go to help) (4) Click [next] system requirements to specify the database server type that can subscribe to the release, SQLSERVER allows data replication between different databases, such as orACLE or ACCESS. But here we choose to run "SQL SERVER 2000" Database SERVER (5) Click [next] The system will pop up a dialog box that defines the article, that is, select the table to be published. Note: if you have selected transaction Publishing, you can only select a table with a primary key (6) and select the publishing Name and description (7). Select the custom publishing attribute Wizard: yes. I want to filter custom data, enable Anonymous subscription, or Disable other custom attributes to create a release according to the specified method (we recommend that you use a custom method) (8) [Next] select the method for filtering and publishing (9) [next] You can select whether to allow anonymous subscription. 1) if you select "signed Subscription", you need to add the subscription server method on the Publishing Server: [tools]-> [copy]-> [configure attributes of the publishing, subscription server, and Distribution]-> [subscription server] to add or else the subscription server requests subscription tip: changing publishing does not allow anonymous subscription. If anonymous subscription is still required, use the following solution: [Enterprise Manager]-> [copy]-> [publish content]-> [attribute]-> [subscribe option] Select allow anonymous request subscription 2) if you select The above prompt is not displayed when configuring the subscription server (10) [next] configuring snapshot Agent Scheduling (11) [Next] complete the configuration. After the publication is created, the database for creating the publication becomes a shared database with the database name srv1 .. author has fields: id, name, phone, srv2. library name .. author has the following fields: id, name, telphone, and adress: srv1. library name .. the database name srv1 .. the srv1. library name is added to the author record .. if the phone field of author is updated, the srv1. library name is displayed .. telphone update for the author field -- */-- General processing steps -- 1. create a connection server on srv1 to operate srv2 in srv1, and synchronize exec sp_add1_server 'srv2', '', 'sqlodb', 'srv2 SQL Instance name or ip' exec sp_add1_srvlo Gin 'srv2', 'false', null, 'username', 'Password' go -- 2. in the srv1 and srv2 brains, start msdtc (Distributed Transaction Processing Service) and set it to Automatic startup. My computer -- control panel -- Administrative Tools -- service -- Right-click Distributed Transaction Coordinator -- Property -- start -- and set the Startup Type to auto start go -- then create a job to call the above synchronization at regular intervals after processing the stored procedure, you can choose "Enterprise Manager"> "manage"> "SQL Server proxy"> "right-click a job"> "Create a job"> "general"> enter the job name ">" Step name ". "Enter the step name --" type "and select" Transact-SQL script (TSQL) "--" Database "select the database for command execution --" command "and enter the statement to be executed: exec p_process -- OK -- "scheduling" item -- create scheduling -- enter the scheduling name in "name" -- select your job execution schedule in "scheduling type" -- if you select "recurrence "-- click "change" to set your schedule and then start the SQL Agent service, and set it to automatic start. Otherwise, your job will not be executed as follows: my computer -- control panel -- Administrative Tools -- service -- Right-click SQLSERVERAGENT -- properties -- start type -- select "auto start" -- OK. -- 3. method 2 for synchronization: timed synchronization -- create proc p_processas in srv1 -- update modified data update bset name = I. name, telphone = I. telphonefrom srv2. library name. dbo. author B, author iwhere B. id = I. idand (B. name <> I. name or B. telphone <> I. telphone) -- insert the new data insert srv2. library name. dbo. author (id, name, telphone) select id, name, telphonefrom author iwhere not exists (select * from srv2. library name. dbo. authorwhere id = I. id) -- delete Deleted Data (if needed) delete bfrom srv2. database name. dbo. author bwhere not exists (select * from authorwhere id = B. id) go

Summary

The above is a compilation of Mysql SQL statement comments. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.