CREATE TABLE dbo.people (
id INT NOT NULL IDENTITY(1,1),
name NVARCHAR(50) NOT NULL,
address NVARCHAR(100) NULL,
tel int(11) NULL,
email NVARCHAR(50) NULL
)
提醒我
Msg 2716, Level 16, State 1, Line 1
Column, parameter, or variable #4: Cannot specify a column width on data type int
怎么修改
id INT NOT NULL IDENTITY(1,1),
name NVARCHAR(50) NOT NULL,
address NVARCHAR(100) NULL,
tel int(11) NULL,
email NVARCHAR(50) NULL
)
提醒我
Msg 2716, Level 16, State 1, Line 1
Column, parameter, or variable #4: Cannot specify a column width on data type int
怎么修改
CREATE TABLE people (
id INT ,
name VARCHAR(50) NOT NULL,
address VARCHAR(100) NULL,
tel int NULL,
email VARCHAR(50) NULL
)
id INT primary key NOT NULL ,
name VARCHAR2(50) NOT NULL,
address VARCHAR2(100) NULL,
tel number(11,0) NULL,
email VARCHAR2(50)
)
序列的话,
create sequence people_seq
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
CACHE 10
创建方法是这样CREATE TABLE dbo.people (
id INT primary key NOT NULL ,
name VARCHAR2(50) NOT NULL,
address VARCHAR2(100) NULL,
tel number(11,0) NULL,
email VARCHAR2(50)
)
create table people(
id int not null,
name varchar2(50) not null,
address varchar2(100),
tel number(11),
email varchar2(50)
)
--
关于自增列,可以建立一个sequence,相当于sql server中的identity函数
create sequence seq_auto_add_id
start with 1
increment by 1
nomaxvalue
nocycle
--
添加数据时你可以这样引用我们刚刚创建的sequence
insert into people(id,name,adress,tel,email)
values(seq_auto_add_id.nextval,,,,);
或者用触发器:
create or replace trigger tri_people_id
before insert on people
for each row
begin
select seq_auto_add_id.nextval into :new.id from dual;
end tri_people_id;
插入数据时:
insert into people(name,adress,tel,email)
values(,,,);
insert语句中sequence的使用方法
SQL> create table people
2 (id int primary key,
3 name varchar(50) not null,
4 address varchar(100) null,
5 tel number(11) null,
6 email varchar(50) null);表已创建。SQL> create sequence people_id_seq;序列已创建。SQL>
SQL> create or replace trigger people_id_seq before insert on people
2 for each row
3 begin
4 select people_id_seq.nextval into :new.id from dual;
5 end people_id_seq;
6 /触发器已创建SQL> insert into people (name, address, tel, email) values('wang', 'beijing', 13611111111, '[email protected]');已创建 1 行。SQL> select * from people;