SQL»ù´¡ÎÊÌâÕûÀí(1)——Äã´ð¶ÔÁ˶àÉÙ£¿
ÔÚ³ÌÐòÖУ¬Êý¾Ý¿â²Ù×÷ÊDZز»¿ÉÉٵIJ¿·Ö£¬ËùÒÔÎÒÃÇÒª±¸×ãÊý¾Ý¿âÏà¹ØÖªÊ¶²ÅÄÜÈ¥Ó¦¸¶³ÌÐòÖгöÏÖµÄÖÖÖÖÎÊÌâ¡£»ùÓÚ´Ë£¬ÎÒÌØµØÔÚ¹úÍâÍøÕ¾¡¢²©¿ÍÉÏÕûÀíÁËһЩÎÊÌ⣬²¢¸½´øÁ˴𰸺ͽâÊÍ¡¢²Î¿¼¡£ÎªÁ˱£Ö¤“ÔÖÔ攣¬ÎҾͱ£ÁôÁËÓ¢ÎÄ¡£´ó¼ÒÒ²À´¿´¿´Äã´ð¶ÔÁ˶àÉÙ£¿
1.SQL Server 2008 Backup
ÌâÄ¿£ºIs it possible to restore a SQL Server 2008 Enterprise Edition compressed backup to a SQL Server 2008 Standard Edition?
´ð°¸£ºyes
½âÊÍ£ºRESTORE from compressed backups on SQL Server 2008 Standard Edition is possible, although the backup compression feature is not supported in SQL Server 2008 Standard Edition.
²Î¿¼£º±¸·ÝѹËõ (SQL Server)
2.Identity
ÌâÄ¿£ºWe want to insert record into table a
create table a (a int identity(1,1))
Which statement will work?
insert into a default values
insert into a values (default)
insert into a values (1)
could not insert explicit for identity column
´ð°¸£ºinsert into a default values
½âÊÍ£ºAn insert statement with "default values" works.
²Î¿¼£ºINSERT
3.Dynamic SQL
ÌâÄ¿£ºSam has to run a query dynamically & get the count in a variable and do some processing based on the count. Which of the following queries will return expected output?
declare @tablevariable varchar(100)
set @tablevariable = 'Employees'
A)
declare @sql varchar(100)
Declare @cnt int
Set @sql = 'Select ' + Convert(varchar(100),@cnt) + ' =count(*) from ' + @tablevariable
Exec (@sql) select @cnt
B)
declare @sql varchar(100)
Declare @cnt int
Set @sql = 'Select count(*) from ' + @tablevariable
@cnt = Exec (@sql) select @cnt
C)
DECLARE @sql nvarchar(4000), @params nvarchar(4000), @count int
SELECT @sql = N' SELECT @cnt = COUNT(*) from dbo.' + quotename(@tablevariable)
SELECT @params = N'@cnt int OUTPUT'
EXEC sp_executesql @sql, @params, @cnt = @count OUTPUT select @count
´ð°¸£ºC
½âÊÍ£ºFor getting a variable as output in a dynamic statement, we need to use sp_executeSQL.
²Î¿¼£ºIntroducing Dynamic SQL
4.T-SQL Output Clause
ÌâÄ¿£ºExecuting the
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......
1¡¢INSTR4(string1,string2[,a][,b]) ·µ»Østring1Öаüº¬string2µÄλÖÃaºÍbÊÇÒÔUCS4´úÂëµãΪµ¥Î»¡£
ÒÔÉϺ¯Êý·µ»Østring1Öаüº¬string2µÄλÖᣴÓ×ó±ß¿ªÊ¼É¨Ãèstring1,ÆðʼλÖÃÊÇA¡£Èç¹ûAΪ¸ºÊýÄÇô´ÓÓұ߿ªÊ¼É¨Ãè¡£µÚB´Î³öÏÖµÄλÖý«±»·µ»Ø¡£AºÍBȱʡ¶¼Îª1£¬¼´·µ»ØÔÚ
string1ÖеÚÒ»´Î³öÏÖstring2µÄλÖá£Èç¹ûstring2ÔÚAº ......
SELECTÓï¾äµÄÍêÕûÓ﷨Ϊ£º
SELECT[ALL|DISTINCT|DISTINCTROW|TOP]
{*|talbe.*|[table.]field1[AS alias1][,[table.]field2[AS alias2][,…]]}
from tableexpression[,…][IN externaldatabase]
[WHERE…]
[GROUP BY…]
[HAVING…]
[ORDER BY…]
[WITH OWNERACCESS OPTION]
×¢ ......