文章分类 -  SQL

SQL中对CASCADE的学习
摘要:CREATE TABLE member (idINTEGER PRIMARY KEYauto_increment,usernameVARCHAR(20)NOT NULL,passwordVARCHAR(20)NOT NULL,realnameVARCHAR(20)NULL,telVARCHAR(20)NULL,addressVARCHAR(100)NULL,zipVARCHAR(6)NULL,emailVARCHAR(50)NULL);CREATE TABLE orders (idINTEGERPRIMARY KEYauto_increment,ordernoVARCHAR(50)NOT NU 阅读全文
posted @ 2012-05-31 14:27 卡域克 阅读(2587) 评论(0) 推荐(0)
每个分类取5条, 这样的SQL如何写??
摘要:CREATE TABLE table1( [ID] [bigint] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](128) NOT NULL, [class] int not null, [date] datetime not null)/* */select id,name,class,date from(select id,name,class,date ,row_number() over(partition by class order by date desc)as rowindex from table1)awher... 阅读全文
posted @ 2012-01-06 10:19 卡域克 阅读(232) 评论(0) 推荐(1)
相同记录取最大值并且只显示一条 相关sql
摘要:declare @tb table(id int, code varchar(10), [values] int)insert @tb select1, 'a' , 2 union all select 2 , 'a' , 3 union all select 3 , 'a' , 3 union all select4 , 'b' , 1 union all select5 ,'b' , 4 union all select6 ,'b' , 4 select* from @tb twhe... 阅读全文
posted @ 2011-10-08 09:54 卡域克 阅读(428) 评论(0) 推荐(0)
一对多关系,联接查询,只从子表当中挑选一行
摘要:--第1个表CREATE TABLE [dbo].[t1]([id] [int] IDENTITY(1,1) NOT NULL,[name] [nvarchar](50) NULL,)--第2个表:CREATE TABLE [dbo].[t2]([id] [int] IDENTITY(1,1) NOT NULL,[t1_ID] [int] NULL,[bwin] [int] NULL,[dat] [datetime] NULL CONSTRAINT [DF_t2_dat] DEFAULT (getdate()),)--解决方案select t1.*,t2.id,t2.bwin,t2.datfr 阅读全文
posted @ 2011-10-05 15:30 卡域克 阅读(172) 评论(0) 推荐(0)
PowerDesigner中CDM和PDM数据类型的mapping
摘要:Conceptual data typeDBMS-specific physical data typeContent Length Integer int / INTEGER32-bit integerShort Integersmallint / SMALLINT 16-bit integerLong Integerint / INTEGER32-bit integerByte tinyint / SMALLINT 256 values Number numeric / NUMBER Numbers with a fixed decimal point Fixed Decimal deci 阅读全文
posted @ 2011-06-15 21:06 卡域克 阅读(1229) 评论(0) 推荐(0)
生成50万条记录的大数据表的TSQL语句
摘要:View Code TSQL_生成表结构:/**//****** 对象: 表 [dbo].[LargeTable] 脚本日期: 2006-10-26 15:40:27 ******/if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[LargeTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[LargeTable]GO/**//****** 对象: 表 [dbo].[LargeTable 阅读全文
posted @ 2011-05-21 10:33 卡域克 阅读(201) 评论(0) 推荐(0)
SQL中的模糊查询符号问题
摘要:View Code % 包含零个或任意多个字符_(下划线) 单个字符[] 指定范围的单个字符(只占一个字符的位置)[^] 非(指定范围的单个字符)ESCAPE LIKE 的一个子句就先解释这些吧,,不明白的看例子。。... where fieldname like 'BUG%'//字符串字段中前三个字母带'BUG'的都是符合条件的记录//例:'BUGd','BUGdefg','BUG','BUG42'....... where fieldname like '%BUG'//字符串字段 阅读全文
posted @ 2011-03-31 14:08 卡域克 阅读(384) 评论(0) 推荐(0)