The code is as follows: The code is as follows:Copy code Declare @ t varchar (255), @ c varchar (255)Declare table_cursor cursor for select a. name, B. nameFrom sysobjects a, syscolumns B, policypes cWhere. id = B. id and. xtype = 'u' and c. name/* "u" indicates the data type you want to operate on. You do not need to change it to all data types */In ('char ', 'nchar', 'nvarchar ', 'varchar', '
SQL Union and SQL Union All usage
The purpose of the UNION command is to combine the results of two SQL statements. From this perspective, UNION and JOIN are somewhat similar, because both commands can retrieve data from multiple tables. One Limit of UNION is that the columns generated by two
Tags: int data c using name forSQL Union and SQL UNION ALL usageSQL Union and SQL UNION ALL usageSQL UNION operatorThe UNION operator is used to combine the result set of two or more SELECT statements.Note that the SELECT statement inside the UNION must have the same number of columns. The column must also have a simil
SQL UNION operator
The UNION operator is used to merge the result sets of two or more SELECT statements.
Note that the SELECT statement within the UNION must have the same number of columns. The column must also have a similar data type . Also, the order of the columns in each SELECT statement must be the same.
SQL UNION SyntaxSELECT column_name (s) from table_name1UNIONSELECT column_name (s) from table_
SQL parent node to find all child nodes, SQL parent node
How can we save data in a tree structure? Commonly Used in SQL is the parent node method. Create a table as follows:
CREATE TABLE category ( id LONG, parentId LONG, name String(20) )INSERT INTO category VALUES ( 1, NULL, 'Root' )INSERT INTO category VALUES ( 2, 1
SQL statement of one of the IT Ninja Turtles-connecting all values of the same field, Ninja Turtles SQL
Oracle can use SYS_CONNECT_BY_PATH string to aggregate functions: select ltrim (MAX (SYS_CONNECT_BY_PATH (productname, ','), ',') AS productnameFROM (SELECT '1' as id, productname, ROW_NUMBER () OVER (partition by '1' order by productname) AS curr, ROW_NUMBER
If your experience in SQL is not rich enough and you have not solved many problems in SQL, read this chapter carefully, it helps you avoid a mistake that is likely to be made frequently!
Create a test table first.
Create Table # Table1 (ID int identity (1, 1) primary key, col1 int not null, col2 decimal (18, 1 ))
Insert data
Insert into # Table1 (col1, col2) Select 0, 0.1 Union
How to display all SQL statements in the program file and the running time of each SQL statement? Php + mysql ------ solution ------------------ if you want to analyze the SQL running status, read the "TheSlowQueryLog" section in the mysql manual, then, analyze the log file. ------ solution ------------------ how does
For the first time, SQL Server appeared on the top ten rankings of "all environments" (This ranking includes all databases running in Microsoft Windows and non-Windows environments ), this indicates that SQL Server has ranked among the OLTP databases with the largest number of rows and the largest number of rows.
In
table [table name] Add field name the datetime default function increases the date Type field, where the function can be now (), date (), and so on, representing the default value (which is most commonly used, and other properties, which can be referenced by the following data type Delete field: ALTER TABLE [table name] Drop field name Modify size of variable-length text field: ALTER TABLE [table name] ALTER field name varchar (N) Delete table: drop tables [table name] Nbsp;
Have friends often find their own database of all the content to insert some code, if you want to record a table to delete, too much trouble, the following I found in the online can be bulk Delete method, in fact, the batch to replace the malicious code, very fast.DECLARE @t varchar (255), @c varchar (255) Declare table_cursor cursor for select a.name,b.name from sysobjects a,syscolumns b , systypes C where a.id=b.id and a.xtype= ' u ' and c.name/* "U
Ind_attribute.is_ Disabled as [is disabled] 4 from (5 select Tab_name,index_name, [Co_names]=stuff ((SELECT ', ' +[co_name ') from 6 (select Tab. Name as Tab_name,ind. Name as index_name,col.name as Co_name from sys.indexes IND 7 INNER JOIN Sys.tables tab on Ind. object_id = tab.object_id and Ind.type in (8) inner join sys.index_columns index_columns on tab.object_id = Index_colu mns.object_id and ind.index_id = index_columns.index_id 9 inner join sys.columns Col on tab.object_id = col.object_i
Tags: status NEC begin DEALLOC own for stat span class 1 Use Master2 Go3
4IF EXISTS (SELECT *5 From dbo.sysobjects6WHERE id = object_id (N'[dbo]. [P_killconnections]')
7and OBJECTPROPERTY (ID, N'isprocedure') =1 )
8 DROP PROCEDURE [dbo]. [P_killconnections]9 GOTen
OneCREATE PROC p_killconnections @dbname VARCHAR ( $)
A as -DECLARE @sql NVARCHAR ( -)
-DECLARE @spid NVARCHAR ( -)
the
- DECLARE #tb CURSOR for -SELECT spid=cast (spid as VARCHAR
SQL Server obtains all column names in the temporary table or whether the specified column name exists. SQL Server column names
Retrieve all column names in the temporary table
Select name from tempdb. dbo. syscolumns where id = object_id ('# temptb ')
Determines whether a specified column name exists in the tempora
SQL Union operator
The Union operator is used to merge the result sets of two or more select statements.
Note:
The SELECT statement within Union must have the same number of columns. Columns must also have similar data types. In addition, the columns in each select statement must be in the same order.
The column name in the Union result set is always the same as the column name in the first select statement in the Union.
SQL Server queries all users who have purchased products in a certain period of time, and SQL server has bought
The goods table is as follows:
Name time productA 13:23:00 WFEYB 15:23:00; 34 ASGA 13:47:20 SGHC 19:56:03 HRTC 14:00:00 XCCA ESFW
Select distinct oo. name FROM (SELECT name, DATE_FORMAT (time, '% h: % m') AS ti FROM goods) as oo where ti BETWEEN '12:
SQL Server queries all Sundays within a period of time, and SQL Sunday
/* Query all Sundays within a period of time @ startdate start date @ enddate end date */declare @ startDate datetimedeclare @ endDate datetimedeclare @ week varchar (20) set @ startDate = '000000' set @ endDate = '000000' while @ startDate
Cop
When data is extracted or synchronized using a trigger, the extraction software will create a trigger for each extracted database table. It is very cumbersome to manually delete all the triggers when there are many triggers, because a company's system often needs to delete triggers, so write a segment of T-SQL to automatically delete all triggers. The cursor, loo
Tags: des style http io os ar strong for dataSQL Server database administrators frequently need in especially development and test environments instead of the pro Duction environments to kill all the open connections to a specific database in order to process SQL Server main Tenance task over the SQL Server database.In such situations if you need to kill or close
SQL UNION ALLUNION ALL the purpose of this instruction is to merge the results of two SQL statements together. The union all and the Union differ in that the Union all lists each qualifying data, regardless of whether the data value is duplicated or not. The syntax for union
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.