Ext.: http://www.cnblogs.com/pangpanghuan/p/6432331.htmlSQL Server Add fields, modify fields, modify types, modify default values1. Modify the field name:ALTER TABLE name rename column A to B2.
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 physical 93Li Si language 74Li Si mathematics 84Li Si physical 94
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 physical 93Li Si language 74Li Si mathematics 84Li Si physical 94
Tags: object scons cts and select default value NULL log alter1. Modify the field name:ALTER TABLE name rename column A to B2. Modify the field type:ALTER TABLE name ALTER COLUMN field name type NOT NULL3. Modify the field default valueALTER TABLE name add default (0) for fi
If you want to change the name of the table column as required, you usually choose server-database-table from isisemanager and modify the table. This is too troublesome. You can use the script to check it.
To change the name of the table column because of the requirement change, I usually run to Enterprise manager to s
An identity column in SqlServer2012 has an attribute:When the server restarts, the identity column defined as int automatically adds 1000 to the original maximum value. For example, your original self-increment column of the maximum value is 2, then you restart after inserting a piece of data into the table, your self-
primarily queried from the middle table, and the following versions of SQL SERVER2005 can be done using aggregate functions.2.1 Row to column syntaxTable_source
PIVOT (
aggregate function (value_column)
for pivot_column
in ( column_list>)
)2.2, using pivot to achieve withT as
(
SELECT 1 asId'Test Team 1'TEAM,' Men'ITEM, theCENTUNION
SELECT 1 asId'Test Team 1'TEAM,'Women'ITEM, -CENTUNION
SE
Label:CREATE TABLE Test(Department varchar (10),Customer varchar (10),Cost name varchar (10),Amount int)INSERT into test values (' A ', ' a ', ' phone fee ', 10)INSERT into test values (' A ', ' a ', ' run at public expense ', 11)INSERT into test values (' A ', ' a ', ' Bus fee ', 9)INSERT into test values (' A ', ' B ', ' phone fee ', 10)INSERT into test values (' A ', ' B ', ' public expense ', 10)INSERT into test values (' A ', ' C ', ' Bus fee ', 10)INSERT into test values (' B ', ' d ', ' p
After the SQL Server clustered index is rebuilt, the column name of the change column location statistics information remains unchanged,
It was originally found by using the clustered index primary key. It was confirmed that it was not a primary key issue but a clustered index issue.
Version: Microsoft
table.SQL Server does not have ready-made functions to implement this function. The SQL statements implemented are as follows:Select column_name from information_schema.columnsWhere table_name = 'table name' and columnproperty (Object_id ('table name'), column_name, 'isidentity ') = 1
5. Identify column reference
If you reference the ID
Tags: style blog http io ar color using SP forThere is such a tableCreate TableTB (IDint, valuevarchar(Ten)) Insert intoTbValues(1,'AA') Insert intoTbValues(1,'BB') Insert intoTbValues(2,'AAA') Insert intoTbValues(2,'BBB') Insert intoTbValues(2,'CCC') Insert intoTbValues(3,'DDD') Insert intoTbValues(3,'FFF')Requirement: The ID is 3 so the data is converted to 1 rows. Separated by |1. Transfer the data with ID 3 to XML XMLSelect ' | ' + (value) from TBwhere id=3For XML Path (")Effec
This problem has been encountered before, and it seems to be solved after I reinstall SQL. Today I encountered the same problem. When I modified an existing view of SQL 2000, once the previous good view is modified with the Enterprise Manager, all the column names listed in the SELECT statement are automatically changed to expr1, expr2, and so on. It is useless t
The Code is as follows:
EXEC sp_rename 'table name. [original column name] ', 'new column name', 'column'
Transact-SQL referenceSp_renameChange the name of the user-created object (such as a table, column, or user-defined data type) in the current database.
Syntax
Sp_rename
Mastering SQL Server Row-to-column and column-changing careers1. List of career changeAfter the data is processed, the data source of the front-end chart will be generated directly, but the data must be written into the intermediate table by the program, and the data can be queried directly from the intermediate table
The Code is as follows:EXEC sp_rename 'table name. [original column name] ', 'new column name', 'column'Transact-SQL referenceSp_renameChange the name of the user-created object (such as a table, column, or user-defined data type) in the current database.SyntaxSp_rename [@ objname =] 'object _ name ',[@ Newname =] 'new
Label:Originally found using the clustered index primary key, confirming that it is not a primary key problem, is a clustered index problem. Version:microsoft SQL Server R2 (SP1) -- Create a test table
- drop table [testtable] Create
table [dbo].[ TestTable] (
[id] [int] NOT NULL,
[name] [varchar] (a) NOT null
)
go
-- insert data into insert
[ TestTable] ([id],[name])
select Id%10,left (name,20) from s
Tags: modify alt nbsp Col Hyper Perl Big entity statement1. Create a table Create TableWorkitemhyperlink (IDbigint Primary Key,--PRIMARY KeyWorkitemidbigint Identity(1,1) not NULL,--where the identity (a) represents a self-increment, the first 1 represents counting from 1, the second 1 represents each increase of 1. HyperLinkvarchar(Max) not NULL, Commentvarchar(Max)NULL
) 2. Modifying columns Alter Table Alter co
SQL's self-increment column is very easy to use, just the development process once deleted data, the identity column is not continuous write up is also very depressed, so looked up the identification column reset method found can be divided into three kinds:---Delete the original table data and reset the self-increment columnTRUNCATE TABLE tablename--truncate mod
Label:If you set a column to identity when you create a new table, you can not display the specified value when inserting the data, and SQL Server automatically populates the value of that column. Create Table TblPerson1
(
IntIdentity(1,1Primarykey not Null ,
Nvarchar (null
) At this point, the following code
SQL Server row-to-column parsing, SQL Server
For more information, see the code:
/* SELECT
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!
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.