SQL ServerÑ¡ÔñÁ˷Ǿۼ¯Ë÷Òý¶ø²»ÊǾۼ¯Ë÷Òý
¾Û¼¯Ë÷Òý²»½ö°üº¬Ë÷ÒýµÄkeyÖµ£¬»¹°üº¬±íÊý¾Ý£»
·Ç¾Û¼¯Ë÷ÒýÖ»°üº¬Ë÷ÒýµÄkeyÖµ¡£
SQL ServerÔÚÓÐЩÇé¿öÏ£¬Óоۼ¯Ë÷ÒýºÍ·Ç¾Û¼¯Ë÷Òý´æÔÚʱ£¬»áÑ¡Ôñ×߷Ǿۼ¯Ë÷Òý£¬¶ø²»×ß¾Û¼¯Ë÷Òý¡£
Àý×ÓÈçÏ£º
ÔÚ SQL Server µÄadventureWorksÊý¾Ý¿âÏ£¬ÔËÐÐÈçÏÂÓï¾ä£º
select DepartmentID,Name from HumanResources.Department
Department±íÉÏÓÐÁ½¸öË÷Òý£¬Ò»¸öÊÇdepartmentidÉϵľۼ¯Ë÷Òý£¬ÁíÒ»¸öÊÇnameÉϵķǾۼ¯Ë÷Òý£»
¸ÃÓï¾äµÄÔËÐнá¹ûÈçÏ£º
DepartmentID Name
12 Document Control
1 Engineering
16 Executive
14 Facilities and Maintenance
10 Finance
9 Human Resources
11 Information Services
4 Marketing
7 Production
8 Production Control
5 Purchasing
13 Quality Assurance
6 Research and Development
3 Sales
15 Shipping and Receiving
2 Tool Design
¿ÉÒÔ¿´µ½½á¹ûÊÇ°´ÔÚnameµÄÉýÐòÅÅÁеģ¬ËµÃ÷ʹÓõÄÊÇnameÉϵķǾۼ¯Ë÷Òý¡£
Èç¹û´æÔÚÁíÍâÒ»¸öûÓÐË÷ÒýµÄÁУ¬Ôò»áÑ¡Ôñ×ßdepartmentidÉϵľۼ¯Ë÷Òý£¬ÒòΪsql server»áÈÏΪÕâÑùµÄËٶȱȽϿ졣
select DepartmentID,Name,GroupName from HumanResources.Department
DepartmentID Name GroupName
1 Engineering Research and Development
2 Tool Design Research and Development
3 Sales Sales and Marketing
4 Marketing Sales and Marketing
5 Purchasing Inventory Management
6 Research and Development Research and Development
7 Production Manufacturing
8 Production Control Manufacturing
9 Human Resources Executive General and Adm
Ïà¹ØÎĵµ£º
drop table father;
create table father(
id int identity(1,1) primary key,
name varchar(20) not null,
age int not null
)
drop table mother;
create table mother(
id int identity(1,1),
name varchar(20) not null,
age int not null,
husban ......
SQL×¢Èë¹¥»÷
¡¡¡¡SQL×¢Èë¹¥»÷ÊǺڿͶÔÊý¾Ý¿â½øÐй¥»÷µÄ³£ÓÃÊÖ¶ÎÖ®Ò»¡£Ëæ×ÅB/SģʽӦÓÿª·¢µÄ·¢Õ¹£¬Ê¹ÓÃÕâÖÖģʽ±àдӦÓóÌÐòµÄ³ÌÐòÔ±Ò²Ô½À´Ô½¶à¡£µ«ÊÇÓÉÓÚ³ÌÐòÔ±µÄˮƽ¼°¾ÑéÒ²²Î²î²»Æ룬Ï൱´óÒ»²¿·Ö³ÌÐòÔ±ÔÚ±àд´úÂëµÄʱºò£¬Ã»ÓжÔÓû§ÊäÈëÊý¾ÝµÄºÏ·¨ÐÔ½øÐÐÅжϣ¬Ê¹Ó¦ÓóÌÐò´æÔÚ°²È«Òþ»¼¡£Óû§¿ÉÒÔÌá½»Ò»¶ÎÊý¾Ý¿â²éѯ´ú ......
×¢ÊÍ:Ö»Êʺϵ¥±íµ¥ÁÐÊý¾Ý,
create database test
go
use test
go
create table users
(
:id int identity(1,1) primary key not null,
:name nvarchar(20)
)
go
create proc sp_Inserts
@Names nvarchar(4000)
as
declare @Name nvarchar(20),@ErrorSum int
:set @ErrorSum = 0
:begin tra ......
ʹÓà CONVERT£º
CONVERT (data_type[(length)], expression [, style])
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),\'-\',\'\'),\' \',\'\'),\':\',\'\')
20040912110608
select CONVERT(varchar(12) , getdate(), 111 ) ......
CONVERT
½«Ä³ÖÖÊý¾ÝÀàÐ͵ıí´ïʽÏÔʽת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ¡£ÓÉÓÚijЩÐèÇó¾³£Óõ½È¡ÈÕÆÚ¸ñʽµÄ²»Í¬.ÏÖÒÔÏ¿ÉÔÚ
SQL ServerÖÐ ½«ÈÕÆÚ¸ñʽ»¯.
SQL Server Ö§³ÖʹÓÿÆÍþÌØËã·¨µÄ°¢À²®ÑùʽÖеÄÊý¾Ý¸ñʽ¡£
ÔÚ±íÖУ¬×ó²àµÄÁ½Áбíʾ½« datetime »ò smalldatetime ת»»Îª×Ö·ûÊý¾ÝµÄ style Öµ¡£¸ø style Öµ¼Ó 100£¬¿É»ñµÃ°ü ......