Common T-SQL statement collation

Source: Internet
Author: User



/*
To view a list of database objects on the server
*---------------------------------------*/
EXEC sp_databases


/*
View information about an object in the current database
*---------------------------------------*/
EXEC sp_help hbcms_article


/*
Execute SQL statement (execute-to-exec)
EXEC sp_executesql (
Description: The same SQL statement only
Pre-compile, high efficiency

Cannot dynamically pass in parameters
Cannot stitch parameter characters
*-------------------------------------------*/
DECLARE
@count int,
@id int=100000,
@sql NVARCHAR (+) =n ' SELECT * from HBCMS_ARTICLE_PART_FN where [email protected];
Select @count = 1000 '
EXEC sp_executesql
@sql,
N ' @count int out, @id int ', @count out, @id
PRINT @count



/*
The second execution of the SQL statement,

Execute SQL statement (execute-to-exec)
EXEC T-SQL statement (
Description: Each execution needs to be compiled once and is less efficient

Parameters can be passed in dynamically
You can stitch the parameter characters
*-------------------------------------------*/
DECLARE
@cot int,
@idt int=100000,
@sqlt NVARCHAR (200);

SET @sqlt = N ' SELECT * from HBCMS_ARTICLE_PART_FN where id_int= ' +cast (@idt as nvarchar (20))

EXEC (@sqlt)/* EXEC sp_executesql @sqlt */
/*

SQL 2012 above must be written as exec (@sqlt), and exec sp_executesql @sqlt also supports,

SQL 05/08 EXEC @sqlt seems to be able to execute,
*/




/*
T-SQL Add table columns
*--------------------------------------*/
ALTER TABLE hbcms_article add Langueid_int int


/*
T-SQL Add foreign key
*--------------------------------------*/
ALTER TABLE Hbcms_article
Add Constraint Fk_hbcms_article_langueid
Foreign KEY (Langueid_int)
References Hbcms_langue_dict (id_int)



Above is my humble opinion, only personal notes,! If found wrong, hope you feel free!


This article is from the "idiot" blog, make sure to keep this source http://hotboy.blog.51cto.com/8826994/1613479

Common T-SQL statement collation

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.