Want to know how to compare two table data in sql server? we have a huge selection of how to compare two table data in sql server information on alibabacloud.com
1 //Query all indicateSelectName fromsysobjectswhereXtype='u'2 3 Select * fromsys.tables4 //Querying all table names and rows in the database5 6 SELECTA.name, B.rows7 8 fromsysobjects asAINNER JOINsysindexes asB ona.ID=b.id9 Ten WHERE(A.type= 'u') and(B.indidinch(0,1)) One A ORDER byA.name,b.rowsDESC - - //query all indication and space consumption \ line number the - Select - - object_name(ID) tablename, + - 8*Reserved/1024x768reserved, +
Many friends ask the SQL Server database "Generate script" to export only the SQL scripts for the database, while the table and table data still do not come out. Very simple, look at the tutorial:
Note: I use the SQLServer2008 he
date intervalsDECLARE @begin_dateDate= '2014-12-31',@end_dateDate= '2016-12-31'; withGeneratehelpdata as( Select 1 asID,CAST( Case when Right(@begin_date,5)='12-30' Then DATEADD( Day,1,@begin_date) ELSE @begin_date END asDATE) asEndingDateUNION All SELECTId+1 asID, Case when Right(DATEADD(QQ,1, EndingDate),5)='12-30' Then DATEADD( Day,1,DATEADD(QQ,1, EndingDate)) ELSE DATEADD(QQ,1, EndingDate)END a
---SQL SERVER 2000 Calendar Parent-child relationship tables (binary tree) get all parent nodes and node layer functions for all child nodes---geovin Du tu ju wen--Building a test environmentCreate Table Geovindu([ID] Int,Fatherid Int,[Name] Varchar (10))Insert A Select 1, 0, ' China 'Union All Select 2, 1, ' Guangdong 'Union all Select 3, 1, ' Beijing 'Union all
1
.
Exec
Sp_spaceused
'
Table Name
'
--
(SQL statistics, which may be inaccurate after a large number of transaction operations)
2
.
Exec
Sp_spaceused
'
Table Name
'
, True
--
(Update the space size of the table. The exact empty size of the
-- Use the function method:
-- Create a demo Environment
If object_id ('tb _ bookinfo') is not null drop table tb_bookinfoGoCreate Table tb_bookinfo (number int, name varchar (10), type INT)Insert tb_bookinfoSelect 1, 'n1 ', 6 Union allSelect 2, 'n2 ', 3
If object_id ('tb _ booktype') is not null drop table tb_booktypeGoCreate
If you want to remember the records in a table for random display, or randomly extract a record, we do not need to write a long stringProgramCodeHow can we create a random number and then make a so-called "random record"? You only need to use a small function in SQL Server to implement the random sorting or random extraction function, this function is newid ()
Compare SQL Server, Oracle, and DB2
I. Openness:
SQL ServerIt can only run on windows without any openness. The stability of the operating system is very important to the database.The Windows9x series products focus on desktop applications, and the NT Server is only s
When using database development, data replication between database tables often imports data from some tables to each other. Of course, you can write programs for implementation. However, programs often require the development environment, which is inconvenient. It is most convenient to directly import data using the SQL
Query all indicates that the select name from sysobjects where xtype= ' u ' select * from sys.tables//queries the database for all table names and row counts select A.name, B.rowsfrom syso Bjects as a INNER JOIN sysindexes as B on a.id = b.idwhere (A.type = ' u ') and [B.indid in (0, 1)] ORDER by A.name,b.rows DE sc//query all marked and space consumption \ line number Selectobject_name (ID) tablename,8*reserved/1024 Reserved,rtrim (8*dpages) + ' KB '
Copy codeThe Code is as follows:Insert into # DirtyOldWIPBOM select top (100) PERCENT dbo. WIP_BOM.Model, dbo. WIP_BOM.PartNumber, WIP_BOM.WIPFROM dbo. WIP_BOM left outer join dbo. BOM_CHINA on ltrim (dbo. WIP_BOM.Model) = LTRIM (dbo. BOM_CHINA.Model) and ltrim (dbo. WIP_BOM.PartNumber) = LTRIM (dbo. BOM_CHINA.PartNumber) AND dbo. WIP_BOM.Qty = dbo. BOM_CHINA.Qty AND BOM_CHINA.WIP =WIP_BOM.WIP WHERE (dbo. BOM_CHINA.Model is null) and exists (SELECT * FROM dbo. BOM_CHINA where wip = WIP_BOM.WIP a
Select ' INSERT INTO table_name (ID,CODE) VALUES (' +cast (id as varchar) + ', ' ' +code+ ' "); ' Sql_str from Canton;SQL Server table data exported as INSERT INTO statement
@ columndata =''Fetch next from syscolumns_cursor into @ name, @ xtypeWhile @ fetch_status BeginIf @ fetch_status BeginIf @ xtype not in (189,34, 35,99, 98) -- timestamp does not need to be processed. Image, text, ntext, SQL _variant will not be processed for the moment.BeginSet @ column = @ column + case when Len (@ column) = 0 then 'else', 'end + @ nameSet @ columndata = @ columndata + case when Len (@ columndata) = 0 then ''else', '','', 'end+ Cas
In the data room charging system, there are several such situations:
Start date and end date. I believe you are smart enough to figure out why there are two date controls! Yes, it is to find records in these two date ranges from a table!
Some people just said, it's not easy!
Suppose we define the first control as Begin, and the second control as Over! The query statement is notCopy codeThe Code is as follow
Get Data fields (field and type information for a table)SELECT Table name= CaseWhen a.colorder=1Then D.nameElse "'End, table description= CaseWhen a.colorder=1Then IsNull (F.value,"')Else "'End, field ordinal=a.colorder, field name=a.name, Logo= CaseWhen ColumnProperty (A.id,a.name,'isidentity')=1Then'√'Else "'end, pri
To obtain the data of the columns in a table, you must first understand the five system tables in sqlserver.
Sysobjects, syscolumns, policypes, sysindexes, sysindexkeys
Sysobjects, each database has a system table that records all database objects. For example, we can obtain the primary key and table object name fr
Label:Suppose the data table structure to insert the data is as followsID is a self-increment column,Insert into UserInfo (username,userpass,email,regtime) output inserted.id values (' AAAAA ', ' AAAAA ', ' AAAAA ', GETDATE ());Insert into UserInfo (username,userpass,email,regtime) output inserted.id values (' AAAAA ', ' AAAAA ', ' AAAAA ', CONVERT ( datetime, '
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.