/*
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