--刪除員工表
drop table db_user;
--刪除角色表
drop table db_role;
--清空**站(recycle bin)
purge recyclebin;
--建立角色資訊表
create table db_role(
roleid varchar2(8) not null primary key,
rolename varchar2(10)
);--建立員工資訊表
create table db_user(
id varchar2(8) not null primary key,
name varchar2(10),
age number(4),
*** varchar2(4),
phone varchar2(13),
city varchar2(16),
roleid varchar2(8),
foreign key(roleid) references db_role(roleid)
);--向角色表中插入資料
insert into db_role values('2013101','普通管理員');
insert into db_role values('2013102','部門經理');
insert into db_role values('2013103','顧問');
insert into db_role values('2013104','超級使用者');
--提交
commit;
--向使用者表插入資料
insert into db_user(id,name,age,***,phone,city,roleid) values('20131001','王鶴',28,'男','1582342342','北京','2013101');
insert into db_user(id,name,age,***,phone,city,roleid) values('20131002','李崇',24,'男','1582342342','深圳','2013102');
insert into db_user(id,name,age,***,phone,city,roleid) values('20131003','郭玉',26,'女','1582342342','上海','2013103');
insert into db_user(id,name,age,***,phone,city,roleid) values('20131004','張赫',22,'男','1582342342','北京','2013101');
insert into db_user(id,name,age,***,phone,city) values('20131005','李文婷',27,'女','1582342342','上海');
insert into db_user(id,name,age,***,phone,city,roleid) values('20131006','李峰',23,'男','1582342342','北京','2013102');
insert into db_user(id,name,age,***,phone,city,roleid) values('20131007','海濤',25,'男','1582342342','長沙','2013101');
commit;
--查詢
select * from db_user where ***='男';
select id,name, age from db_user;
select * from db_user where age<24;
select * from db_user where city='北京';
select * from db_user where id='20131002';
select * from db_user where ***='男' and age<24;
select * from db_user where ***='男' or age<24;
--修改資料
update db_user set name='李易峰';
commit;
update db_user set name='李易小峰',age=26,phone='12345667' where id='20131006';
commit;
select * from db_user;
--刪除
delete from db_user where ***='女';
select * from db_user;
delete from db_user;
commit;
select * from db_user;
SQL表結構操作語句
遷移資料,可以複製自動編號啦!set identity insert data on insert into data id,a1,a2 select id,username,email from olddata a.重新命名表 下例將表 customers 重新命名為 custs。exec sp ...
使用SQL語句匯出表結構
老大寫的sql select tablename o.name,owner user name o.uid tabledescription isnull ptb.value,n fieldid c.colid,fieldname c.name,fieldtype quotename t.name ...
Sql 語句查詢表結構
sql2000系統表的應用 1 獲取當前資料庫中的所有使用者表 select name from sysobjects where xtype u and status 0 2 獲取某乙個表的所有字段 select name from syscolumns where id object id 表名...