Http://blog.sina.com.cn/s/blog_a342ff0a0101u3kb.htmlSQL Server:Solution 1:select Top * from a where ID not in (select top with ID from a);Solution 2:select Top * from a Where ID > (select MAX (ID) from (select top with ID from a) as A);As I understand it,The first method: first 30 data (the default positive order) is queried based on the ID, and then the first 10 data in the 30 data is queried in the positive order.The second method: first, according to the ID positive sequence query the top 30
Label:That day: SELECT * from T_news where DateDiff (Day,addtime,getdate ()) =0 Last three days: SELECT * from T_news where DateDiff (Day,addtime,getdate ()) Week: SELECT * from T_news WHERE (DATEPART (wk, addtime) = DATEPART (wk, GETDATE ())) and (DATEPART (yy, addtime) = DATEPART (yy, GET DATE ())) Note: You cannot use the DateDiff difference at this time as 7, because DateDiff only represents the number of intervals Month: SELECT * from T_news WHERE (DATEPART (yy, addtime) = DATEPART (yy, GE
--select select * from student; --all query All the Select all sex from student; --DISTINCT filtering repeats select distinct sex from student; --count Statistics SELECT COUNT (*) from student; Select count (Sex) from student; Select count (Distinct sex) from student; --top fetch top N Records select Top 3 * from student; --alias Column name rename named Select ID as number, name ' names ', sex gender from student; --alias Table Name table rename Select ID, name, s.id, s.name from student s; --c
Tags: time difference binary not for simple JPG rop condition Sele sizeFor statements to run, there are other factors to consider, in addition to the execution plan itself, such as the compile time of the statement, the execution time, the number of disk reads, and so on. If the DBA is able to run the problem statement separately, you can open the following three switches before running to collect statistic
Label:Execution Order: 1.FROM: Performs a cartesian product of the first two tables in the FROM clause to generate a virtual table VT1 2.ON: Apply on filter to VT1 table only rows that satisfy true are inserted vt2 3.OUTER (Join): Adds rows that are not found in the OUTER join reservation table (preserved table) as outer rows to the VT2 Generate T3 If the from contains more than two tables repeat steps and steps for the result table and the next table generated by the previous junction directly
: Check wooyundrops try to enter SQL statements manually using xp_cmdshell to execute commandsTest 4 Result: Unable to connect server, return 404 page; ----------------------------------------------------- ; EXEC Master. xp_cmdshell ' net user '---
Test 5 Purpose: Try to add the% symbol to the keyword, the OUTPUT keyword to determine which keyword is filtered;Test 5 Result: Xp_cmdshell,sp_configure and no
Tags: style blog http color OS data width 2014are you still tapping the code to generate the SQL statement? Are you still having a problem with the SQL statements that were sloppy? Are you still tangled in the idea of how to express complex SQL statements? If your answer is yes, then you're out, come on. Apply
Copy Code code as follows:
--begin Index (index) analysis optimization related SQL
--Returns an index with more than 25% of the current database fragmentation rate
--Running this statement scans a lot of data pages
--Avoid running when the system load is relatively high
--Avoid running when the system load is relatively high
DECLARE @dbid int
Select @dbid = db_id ()
SELECT O.name as tablename,s
INTO keyword can be added without adding it to enhance the readability of the statement. Casual ~Note: Columns cannot be set to a null value if there are three cases in which the value is interpolated1. The column is defined as the default value.2. The column is defined to accept some form of system generated value. For example, the identity value3. The value of the column has been supplied when inserting the data.(The stored Procedure sp_help featur
the last hour of the day that SQL Server can record.
• Last day of last year SQL script: SELECT dateadd (Ms,-3,dateadd (yy, DATEDIFF (Yy,0,getdate ()), 0)To connect the above example, to get the last day of last year, you need to subtract 3 milliseconds from the first sky of the year.
• SQL scripts for the last day
SQL Server 2008 provides an enhanced SQL command merge for use in the msdn:http://msdn.microsoft.com/zh-cn/library/bb510625.aspx
Function: Inserts, updates, or deletes on the target table based on the results of joining with the source table. For example, you can synchronize two tables by inserting, updating, or deleting rows in a table based on differences foun
The following are common SQL statements used by SQL Server and access to operate database structures.
The content is organized by HAI wa. if the content is incorrect or incomplete, please submit it. Thank you.
Create a table:Create Table [Table name]([Automatic number field] int identity (1, 1) primary key,[Field 1] nvarchar (50) default 'default value 'null,
The following are common SQL statements used by SQL Server and Access to operate database structures.The content is organized by HAI wa. if the content is incorrect or incomplete, please submit it. Thank you.Create a table:Create table [table name]([Automatic number field] int IDENTITY (1, 1) primary key,[Field 1] nVarChar (50) default 'default value 'null,[Field
Like what:
SELECT * FROM table1 where name= ' Zhangsan ' and TID > 10000
and implementation:
SELECT * FROM table1 where TID > 10000 and name= ' Zhangsan '
Some people do not know the execution efficiency of the above two statements is the same, because if it is simple to read from the statement, the two statements are indeed different, if the TID is an aggregation index, then the following sentence only from the table after 10,000 records to find the
procedures, functions associated with a table
Select a.* from sysobjects A, syscomments b where a.id = b.ID and b.text like '% table name '
6. View all stored procedures in the current database
Select name as stored procedure name from sysobjects where xtype= ' P '
7. Query all databases created by users
SELECT * FROM Master. sysdatabases D where Sid not in (select Sid from Master. syslogins where name= ' sa ')
Or
Select dbid, name as Db_name from master. sysdatabases where Sid 8. Querying the
Copy Code code as follows:
DECLARE @name VARCHAR (25)
DECLARE @SQL VARCHAR (1000)
DECLARE @logid INT
DECLARE sysdatabase_name CURSOR for SELECT name from master.dbo.sysdatabases
OPEN Sysdatabase_name
FETCH NEXT from Sysdatabase_name into @name
While @ @FETCH_STATUS = 0
BEGIN
IF (@name not in (' xxx ')-database name that does not require log shrinkage
BEGIN
SET @
The sql2008 shrink log is as follows:
The code is as follows
Copy Code
BACKUP LOG dbname to disk= ' Dbname.log 'DBCC shrinkfile (' Dbname_log ', 1)
But remember to perform two times before you can finally perform the contraction;
Shrink database files (if not compressed, database files do not reduce Enterprise Manager--right--the database you want to compress--all tasks--shrink the database--Shrink the file--Select Log file--in the shrinkage method to choo
Reposted from: longtang Bay
1.1.1 obtain the first N records
SQL Server: Select Top N * From xtable
ORACLE: Select * From xtable where rownum
DB2: Select * From xtable fetch first n rows only
1.1.2 obtain the current date
SQL Server: Select getdate ()
ORACLE: Select sysdate from dual
DB2: Select current timestamp from
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.