SQL创建数据库、表、存储过程及调用
--如果存在数据库programmerPay 就删除
if exists (select * from sysdatabases where name='programmerPay')
drop database programmerPay
go
--创建数据库programmerPay
create database programmerPay
on primary
(
name ='programmerPay_data',
filename='D:\programmerPay\programmerPay_data.mdf',
maxsize=3mb,
filegrowth=15%
)
log on
(
name ='programmerPay_log',
filename='D:\programmerPay\programmerPay_log.ldf',
maxsize=1mb,
filegrowth=15%
)
go
use programmerPay
go
--创建表prowage
create table prowage
(
id int identity(1,1) not null,--主键 标识列
Pname char(10) not null,--程序员姓名
wage int not null--程序员工资
)
go
--为表prowage id 字段添加主键约束
alter table prowage
add constraint PK_id primary key(id)
--插入测试数据
insert into prowage (pname,wage)
values ('张三',5000)
insert into prowage (pname,wage)
values ('李四',1200)
insert into prowage (pname,wage)
values ('二月',1700)
insert into prowage (pname,wage)
values ('蓝天',5700)
insert into prowage (pname,wage)
values ('阳光',8700)
insert into prowage (pname,wage)
values ('神州',1100)
insert into prowage (pname,wage)
values ('曾经藏',1300)
insert into prowage (pname,wage)
values ('ruo',1200)
insert into prowage (pname,wage)
values ('chend',1400)
--如果存在存储过程proc_addWage1 就删除
if exists (select * from sysobjects where name='proc_addWage1')
drop procedure proc_addWage1
go
--创建存储过程proc_addWage1
create procedure proc_addWage1
as
set nocount on
declare @firstwage int
select @firstwage=sum(wage) from prowage
while (1=1)
begin
declare @notpass int, @count int--定义两个变量 没达到2200的人数和总人数
select @notpass=count(*) from prowage where wage<2200
select @count =count(*) from prowage
if(@notpass*
相关文档:
oracle数据库中sql基础
作者:佚名 转贴自:本站原创 浏览次数:21 文章录入:admin
一、关系数据库的一些概念
1、主键的值一般不可以改变
2、外键:指向另一个表或本表的主键或唯一键的字段。外键的值一定要和某一主键相同 ......
做数据库开发或管理的人经常要创建大量的测试数据,动不动就需要上万条,如果一条一条的录入,那会浪费大量的时间,本文介绍了Oracle中如何通过一条SQL快速生成大量的测试数据的方法。
产生测试数据的SQL如下:
SQL> select rownum as id,
2 &nb ......
命题:写出一条Sql语句: 取出表A中第31到第40记录(自动增长的ID作为主键, 注意:ID可能不是连续的。)
oracle数据库中:
1、select * from A where rownum<=40 minus select * from A where rownum<=30
sqlserver数据库中:
1、select top 10 * from A where id not in (select top 30 id from A )
2、s ......
SQL中有四种基本的DML操作:INSERT,SELECT,UPDATE和DELETE。
INSERT语句
用户可以用INSERT语句将一行记录插入到指定的一个表中。例如,要将雇员John Smith的记录插入到本例的表中,可以使用如下语句:
INSERT INTO EMPLOYEES VALUES
('Smith','John','1980-06-10',
'Los Angles',16,45000);
......
最近有朋友遇到省市的问题,想想自己今后也有可能会遇到,所以就自己在网上写写,搜搜,主要是对自己今后有参考
--创建数据库
create database NationalAll
Go
--使用NationalAll数据库
use NationalAll
Go
--创建省级表
Create Table Province
(
ProID int primary key not null,
ProName nvarchar(50) n ......