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
Ïà¹ØÎĵµ£º
1 µ±Ê¹ÓÃgroup byʱ£¬Î´ÔÚgroup by ²¿·ÖÓõ½µÄ±íÁÐÔÚs e l e c t²¿·Ö³öÏÖʱ±ØÐëʹÓ÷Ö×麯Êý¡£
select last_name, state_cd, sum(sales) from customer group by last_name;
ERROR at line 1:
ORA-00979: not a GROUP BY expression.
state_cdÓ¦¸ÃʹÓ÷Ö×麯Êý£¬m a x ( )¡¢m i n ( )¡¢s u m ( )¡¢c o u n t ( )»òa v g ......
----use pubs-sales
-----´´½¨Ë÷Òý
create index index_name
on authors(au_lname)
--´´½¨Ë÷Òýºó±íÖÐËùÓеÄÊý¾Ý¸ú֮ǰûÓÐÇø±ð
select * from authors
--µ¥¶À²éË÷ÒýÁÐ
select au_lname from authors
--Ç¿ÖÆÊ¹Ó÷Ǵؼ¯Ë÷Òý
select * from authors with(index(index_name))
--¶à×ֶηǴؼ¯Ë÷Òý
create inde ......
×÷Õß:ÍøÂ·ÓÎÏÀ@youxia.org
·¢²¼Ê±¼ä:2005-9-25 11:48:18 ÎÄÕÂÀ´Ô´:youxia.org
̨ʽ»úºÍ±¾±¾·Ö±ð°²×°ÁËMS SQL Server£¬·½±ã×ö²âÊÔÓÃ
½á¹ûʱ¼ä³¤ÁË£¬
̨ʽ»úSQL ServerµÄÃÜÂëÍü¼ÇÁË……
ÄѵÀ……ûÓа취ÁËÂ𣿗—No£¡
¾¹ýÒ»Õó×ÓÓôÃÆ£¬ÓÎÏÀÔÚ°Ù¶ÈËѵ½ÁË·½·¨£º
ÏÖÔÚÄãµÄ
ÆóÒ ......
Ò»¡¢sqlÓï¾äµÄÖ´Ðв½Ö裺
1£©Óï·¨·ÖÎö£¬·ÖÎöÓï¾äµÄÓï·¨ÊÇ·ñ·ûºÏ¹æ·¶£¬ºâÁ¿Óï¾äÖи÷±í´ïʽµÄÒâÒå¡£
2£© ÓïÒå·ÖÎö£¬¼ì²éÓï¾äÖÐÉæ¼°µÄËùÓÐÊý¾Ý¿â¶ÔÏóÊÇ·ñ´æÔÚ£¬ÇÒÓû§ÓÐÏàÓ¦µÄȨÏÞ¡£
3£©ÊÓͼת»»£¬½«Éæ¼°ÊÓͼµÄ²éѯÓï¾äת»»ÎªÏàÓ¦µÄ¶Ô»ù±í²éѯÓï¾ä¡£
4£©±í´ïʽת»»£¬ ½«¸´Ô SQL ±í´ïʽת»»Îª½Ï¼òµ¥µÄµÈЧÁ¬½Ó±í´ïʽ ......
......