实验2 创建数据库和表

以下为Navicat Premium界面中的代码

--创建数据库

CREATE DATABASE YGGL

ON

(    name = 'YGGL_data',

    filename = '/Users/aubrey/Desktop/sql/YGGL.mdf',

    size = 10 mb,

    maxsize = 50 mb,

    filegrowth = 5%

)

log on

(    name = 'YGGL_log',

    filename = '/Users/aubrey/Desktop/sql/YGGL.ldf',

    size = 2 mb,

    maxsize = 5 mb,

    filegrowth = 1 mb

)

go

--中文乱码的解决:中文编码转换

ALTER DATABASE [YGGL] COLLATE Chinese_PRC_CS_AS_WS

GO

--创建表

use YGGL

go

create table Employees

(    EmployeeID char(6) not null PRIMARY KEY,

    Name char(10) not null,

    Education char(4) not null,

    Birthday date not null,

    Sex bit not null default 1,

    WorkYear tinyint null,

    Address varchar(40) null,

    PhoneNumber char(12) null,

    DepartmentID char(3) not null

)

go

create table Departments

(    DepartmentID char(3) not null PRIMARY KEY,

    DepartmentName char(20) not null,

    note varchar(100) null

)

go

create table Salary

(    EmployeeID char(6) not null primary key,

    InCome float not null,

    OutCome float not null

)

go

—输入数据

INSERT INTO Employees VALUES('000001','王林','大专','1966-01-23',1,8,'中山路-1-508','83355668','2'),

                                                        ('010008','伍容华','本科','1976-03-28',1,3,'北京东路-2','83321321','1'),

                                                        ('020010','王向容','硕士','1982-12-09',1,2,'四牌楼-0-108','83792361','1'),

                                                        ('020018','李丽','大专','1960-07-30',0,6,'中山东路-2','83413301','1'),

                                                        ('102201','刘明','本科','1972-10-18',1,3,'虎距路-2','83606608','5'),

                                                        ('102208','朱俊','硕士','1965-09-28',1,2,'牌楼巷-3-106','84708817','5'),

                                                        ('108991','钟敏','硕士','1979-08-10',0,4,'中山路-3-105','83346722','5'),

                                                        ('111006','张石兵','本科','1974-10-01',1,1,'解放路-1-203','84563418','5'),

                                                        ('210678','林涛','大专','1977-04-02',1,2,'中山北路-24-35','83467336','3'),

                                                        ('302566','李玉珉','本科','1968-09-20',1,3,'热河路-209-3','58765991','4'),

                                                        ('308759','叶凡','本科','1978-11-18',1,2,'北京西路-7-52','83308901','4'),

                                                        ('504209','陈林琳','大专','1969-09-03',0,5,'汉中路-4-12','84468158','4')


Employees表

insert into Departments Values('1','财务部',NULL),

                                                            ('2','人力资源部',NULL),

                                                            ('3','经理办公室',NULL),

                                                            ('4','研发部',NULL),

                                                            ('5','市场部',NULL)


Departments表

insert into Salary Values('000001',2100.08,123.09),    

                                                 ('010008',1582.62,88.03),

                                                 ('102201',2569.88,185.65),

                                                 ('111006',1987.01,79.58),

                                                 ('504209',2066.15,108.0),

                                                 ('302566',2980.7,210.2),

                                                 ('108991',3259.98,281.52),

                                                 ('020010',2860.0,198.0),

                                                 ('020018',2347.68,180.0),

                                                 ('308759',2531.98,199.08),

                                                 ('210678',2240.0,121.0),

                                                 ('102208',1980.0,100.0)


Salary表

你可能感兴趣的:(实验2 创建数据库和表)