[Small question note (eight)] Common SQL (read field name, change field name, print affects the number of rows, add default values, find stored procedures, etc.)

Source: Internet
Author: User

Read all fields, natural sort

Declare  @fields varchar(Max) Select @fields=ISNULL(@fields,"')++Name+','  fromsyscolumnsWhereId=object_id(' Contact')Order  byColorderPrint @fields

Read all fields, sort by name

Declare  @fields varchar(Max) Select @fields=ISNULL(@fields,"')++Name+','  fromsyscolumnsWhereId=object_id(' Contact')Order  bynamePrint @fields;

Add field, change type, rename, delete field

Alter TableCompeteagentinfoAddIsfangtupayint Null, ISFANGTUint NullAlter TableContacttrailAlter columnTraildescriptionnvarchar( -) sp_rename'Contacttrail.trailisvalid','IsValid','column'ALTER TABLEtable_nameDROP COLUMNcolumn_name

Print affects the number of rows:

Print @ @rowcount

Change table name

EXEC ' SSHOP1 ' '  Shop '


Existing fields Add default values

Alter Table Add constraint DEFAULT 1  for IsValid

Find stored procedures (including Xiaobu)

SELECT from information_schema. ROUTINESWHERElike'%xiaobu%' and Routine_type=  'PROCEDURE'

[Small question note (eight)] Common SQL (read field name, change field name, print affects the number of rows, add default values, find stored procedures, etc.)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.