How does SQL Server modify the auto-increment column value and corresponding solutions?
A special task encountered in today's work is to change the values of the two auto-incrementing columns.Since the SQL Server platform has prev
SQL Server platform modifies self-added column values
Since the migration of the SQL Server database was previously processed, a change to its own column value has been attempted, but modifying the self-added
Tags: style blog http use data reIn general, we create a database using SQL Server, and occasionally the column names in the table are incorrectly created when we create the base tables. Want to change the name of the list, there are generally many kinds of modification, but the complexity is not the same, some people to delete the entire table, re-established to
The code is as follows:
EXEC sp_rename ' table name. [Original column name] ', ' new column name ', ' column '
Transact-SQL Reference
sp_rename
Changes the name of a user-created object (such as a table, column, or user-defined data type) in the current database.
Grammar
Label:To modify the table design of a database, you can use the SQL ALTER TABLE statement, which is used to add, delete, or modify table columns in an existing table. 1> add a new column to the database table:Grammar:ALTER table name ADD column name data typeFor example: Ad
Sometimes, when there is data in the database, and then delete the column in the designer, it will not be deleted. Can only be removed with code.Alter Table Drop column ColumnName Adding columnsAlter Table Add varchar (in) modifying columns--Modify the type of the columnAltertablealtercolumnvarchar(4000) --Modify t
ALTER TABLE name add column name data class typeExample: ALTER TABLE Student add nickname char (20)ALTER TABLE tableName (table name) add columnName (column name) varchar (30)Modifying the type of a column ALTER TABLE tbname--table nameAlter COLUMN COLNAME--column nameNvarCh
UNION All SELECTN'Zhang San'N'English', -GOSELECT * from [Testrows2columns](Figure 2: Sample Data)(b) First, a static way to achieve row to column, the effect of 3 is shown:--1: Static splicing row to columnSELECT [UserName],SUM( Case [Subject] when 'Mathematics' Then [Source] ELSE 0 END) as '[Mathematics]',SUM( Case [Subject] when 'English' Then [Source] ELSE 0 END) as '[English]',SUM( Case [Subject] when 'language' Then [Source] ELSE 0
UNION All SELECTN'Zhang San'N'English', -GOSELECT * from [Testrows2columns](Figure 2: Sample Data)(b) First, a static way to achieve row to column, the effect of 3 is shown:--1: Static splicing row to columnSELECT [UserName],SUM( Case [Subject] when 'Mathematics' Then [Source] ELSE 0 END) as '[Mathematics]',SUM( Case [Subject] when 'English' Then [Source] ELSE 0 END) as '[English]',SUM( Case [Subject] when 'language' Then [Source] ELSE 0
' English ', 100
GO
SELECT * FROM [Testrows2columns]
(Figure 2: Sample Data)
(b) First, a static way to achieve row to column, the effect of 3 is shown:
--1: Static splicing row to column
SELECT [UserName],
SUM (case [Subject] when ' math ' then [Source] ELSE 0 END) as ' [Math] ',
SUM (case [Subject] when ' English ' then [Source] ELSE 0 END)
Tags: Time characteristics Law object_id LTE Eric modify alter typeOriginal: Use SQL statement to create a modified SQL Server identity column (that is, autogrow column)I. Definition and characteristics of the identity columnThe i
)
SELECT @sql =isnull (@ Sql+ ', ', ') + course from TB GROUP by course
SET @sql = ' SELECT * from TB pivot (MAX (score) for course in (' [email protected]+ ')) a '
exec (@sql)
The results of the row and column are combined with the total score, t
Label:I. Definition and characteristics of the identity columnThe identity column in SQL Server is also called the identifier column, which is also known as the self-increment column.This type of column has the following three characteristics:1. The data type of the
Modify SQL database sorting rules Modify Table column sorting rules modify SQL database sorting rules: 1. change to single-user mode 2. close all query windows and modify the Collocatio
Label:The teammate gave me the statement to modify the data. Always fails to execute. I wonder. For example:Look carefully at this column, and there is nothing special. such as:But it does have a constraint: ' df__his_drug___all_i__04e4bc85 '. Why do we have this constraint???When I finally searched this article, I understood. Because the column ' All_inventory_s
: --4: Dynamic pivot row to column
DECLARE @sql_str varchar (8000)
DECLARE @sql_col varchar (8000)
SELECT @sql_col = ISNULL (@ Sql_col + ', ', ') + QUOTENAME ([Subject]) from [Testrows2columns] GROUP by [Subject]
SET @sql_str = '
SELECT * from (
SELECT [Username],[subject],[source] from [Testrows2columns]) p PIVOT
(SUM ([Source]) for [Subject] in (' + @sql_col + ')) As Pvt
ORDER by pvt.[ UserName] '
PRINT (@sql_str)
EXEC (@sql_str) (vi) M
@sql = ' Select * FROM TB Pivot (MAX (score) for course in (' [email protected]+ ')) a ' EXEC (@sql)The results of the row and column are combined with the total score, the average1. Using SQL Server 2000 static SQLSELECT name, Max (case course when ' language ' then score
Http://blog.csdn.net/xys_777/archive/2010/06/22/5685953.aspx
Summary of Row-to-column conversion problems-1. Row-to-column conversion (various problems in the forum will be sorted out later)
--- 1. Simplest row-to-column Conversion/*
Question: Suppose there is a student orders table (TB) as follows:Name course scoreZhang San Language 74James math 83Zhang San phys
Pivot is used to rotate column values to column names (row to column)Grammar:Table_sourcepivot (Aggregation function (value_column) for Pivot_columnin (Unpivot used to set the column value to a column (that is, a column change)Gra
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.