如果为sql server 2000创建主键呢和索引呢?用sql语句(200分)

  • 主题发起人 delphitodelphi
  • 开始时间
D

delphitodelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
a.SQL.Text :='CREATE TABLE [dbo].[baktable] ('+
' [jwh] [char] (3) COLLATE Chinese_PRC_CI_AS NOT NULL,'+
'[qw] [char] (1) COLLATE Chinese_PRC_CI_AS NULL ,'+
'[sjsj] [datetime] NULL ,'+
'[fjje] [float] NULL ,'+
'[fjxx] [text] COLLATE Chinese_PRC_CI_AS NULL ,'+
'[xs] [int] NULL ,'+
'[sj] [int] NULL ,'+
'[lx] [char] (4) COLLATE Chinese_PRC_CI_AS NULL ,'+
'[hyid] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,'+
'[hylx] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,'+
'[addfy] [float] NULL ,'+
'[ssfy] [float] NULL ,'+
'[ysfy] [float] NULL ,'+
'[admin] [char] (10) COLLATE Chinese_PRC_CI_AS NULL'+
') ON [PRIMARY]';
a.ExecSQL;
我不知道怎么为jwh这个字段创建主键,怎么再为ssfy和ysfy创建索引呢?我很笨就以这个
为例好吗?谢谢了。
 
1)创建主键办法1
create table MySkill(
groupid int,
skillgroupid int,
primary key (groupid, skillgroupid) --这是主键
)
2)创建主键办法2
create table Mygroup(
groupNumber int not null primary key, ---这是主键
parentgroupid int not null,
attribute tinyint default 0,
abcde int
)

3)建唯一索引
create table operatorcode(
operatorNo int,
code int,
describe varchar(40)
)
create unique index index_operatorcode on operatorcode(operatorNo,code) --这是建唯一索引
4)这是建一般索引
create table dbo.MyRecord (
worknumber int not null ,
phone char (24) null ,
OperationCode char (100) not null,
code char(4) not null
)
go
create index idx_time on dbo.MyRecord (worknumber , code )
go

你的问题的答案是:
a.SQL.Text :='CREATE TABLE baktable ('+
' jwh char (3) NOT NULL primary key , '+
'qw char (1) NULL ,'+
'sjsj datetime NULL ,'+
'fjje float NULL ,'+
'fjxx text NULL ,'+
'xs int NULL ,'+
'sj int NULL ,'+
'lx char (4) NULL ,'+
'hyid char (10) NULL ,'+
'hylx char (10) NULL ,'+
'addfy float NULL ,'+
'ssfy float NULL ,'+
'ysfy float NULL ,'+
'admin char (10) NULL '+
')';
a.ExecSQL;
a.SQL.Text :=' create index index_baktable1 on operatorcode(ssfy , ysfy) ';
//这是组合索引
a.ExecSQL;


 
谢谢你。
 
顶部