1. Primary Key constraints:To add a primary key constraint to a column, this column must meet the condition that it is left empty.Because of the primary key constraint: A column is restricted, and the constraint is (not empty, not repeated)The following code adds a primary key to a
Check whether the table exists
1. Use System View: SYS. Tables
Select name from SYS. tables where name = 'tablaname' and type = 'U'
Type = 'U' is used to exclude stored procedures, views, and system tables. It refers to the user table user_table.
2. Use the System View: sysobjectsSelect * From sysobjects where id = object_id ('usersubsyscenthistory _ null') and xtype = 'U'
Xtype = 'U' is used to exclude sto
It mainly uses case statements to solve the problem of Row-to-column conversion.The row-to-column conversion problem is mainly divided into two types:
1) Simple row-to-column conversion:
Example Table:
Id Sid Course Result
1 2005001 Chinese 80.02 2005001 mathematics 90.03 2005001 English 80.04 2005002 Chinese 56.020050
Today is the Lantern Festival. Lou pig thinks that in such a lively and festive day, it is no big deal to write a shocking masterpiece from the previous one.Create an auto-incrementing table on the SQL Server database. After each table is deleted, the auto-incrementing primary key cannot be automatically counted from 1
I am working on a program for the SQL Server database. I want to read the column information in the database, find a lot of information from the Internet, and finally find out the ideal SQL statement, after execution, the returned columns are: Table Name,
Today, a vendor asked me a question. If you want to change the data type of a field in a table, whether it is a field type in View also responds to automatic changes. At that time, I thought it would be changed automatically.
However, the vendors said they had tried and won't change it. They asked me if I had any other choice but to try again. At that time, I thought of the storage process sp_refreshview for refreshing the View and asked them to give
] ') and xtype in (n'fn', n'if', n'tf '))Drop function [DBO]. [function name]
7. obtain information about the object created by the user
Select [name], [ID], crdate from sysobjects where xtype = 'U'
/*Xtype indicates the parameter type, which usually includes the followingC = check ConstraintsD = default value or default ConstraintF = foreign key constraintL = LogFn = scalar functionIf = embedded table functionsP = Stored ProcedurePK = primary
--Create a tableCreate TableTable (A1varchar(Ten), A2Char(2))--add descriptive information to a tableEXECUTESp_addextendedproperty N'ms_description','Personnel Information Sheet'N'User'N'dbo'N'Table'N'Table',NULL,NULL--Add descriptive information for field A1EXECUTESp_addextendedproperty N'ms_description','name'N'User'N'dbo'N'Table'N'Table'N'column'N'A1'--Add des
SQL ALTER TABLE syntax and example tutorial
After the alter table statement allows you to change the structure of a TABLE, it is created. Address terms that can be added to a new column
SQL ALTER TABLE Syntax and instance tutorial
The ALTER TABLE statement allows you to change the structure of a table after it has been created. New column can be added to the address c
CREATE TABLE Tb_name(ID INT not NULL IDENTITY PRIMARY KEY,Title NVARCHAR (+) NULL)View the columns in the Tb_name table that are self-growingSELECT TOP (1) identitycol from Tb_nameView the current value of the self-growing column in the Tb_name tableDBCC checkident (Tb_name)Modify the current value of the self-growing column
The operation code for XML columns in SQLServerTable. For more information, see.
The operation code of XML columns in SQL Server Table. For more information, see.
The Code is as follows:
-- Create a test table
DECLARE @ Users TABLE
(
Id int identity (1, 1 ),
UserInfo XML
)
I recently studied sqlserver database .. I have not been familiar with it for a long time. I often encounter some alter statements, and I have learned some about it in my spare time. the following example uses the table structure createdatabaseText_DBgouseText_DBgocreatetableTeacher (
I recently studied sqlserver database .. I have not been familiar with it for a long time. I often encounter some
SELECTTable name= Case whenA.colorder=1 ThenD.nameElse "' End, table describes= Case whenA.colorder=1 Then IsNull(F.value,"')Else "' End, Field ordinal=a.colorder, field name=a.name, Logo= Case when ColumnProperty(A.id,a.name,'isidentity')=1 Then '√'Else "' End, PRIMARY key= Case when exists(SELECT 1 fromsysobjectswhereXtype='PK' andParent_obj=a.ID andNameinch ( SELECTName fromsysindexesWHEREIndidinch(SELECTIndid fromS
Today, a vendor asked me a question. If you want to change the data type of a field in a table, whether it is a field type in view also responds to automatic changes. At that time, I thought it would be changed automatically. However, the vendors said they had tried and won't change it. They asked me if I had any other choice but to try again. At that time, I thought of the storage process sp_refreshview for refreshing the view and asked them to give
The ALTER TABLE statement is used to add, modify, or delete a column's original table in an existing table:first, Alter adds a new column to the table
syntax:ALTER
Tags: style blog http io color ar os sp strongOriginal: SQL Server index and table architecture (including column index)Include column indexOverviewThe include column index is also a nonclustered index, and the index structure is
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.