SQL server基本操作(一)

 

--1.create database
CREATE DATABASE MyDB
GO
--2.use database
USE MyDB
GO
--3.create table
CREATE TABLE Teacher
(
id INT IDENTITY PRIMARY KEY,
tname VARCHAR(10) NOT NULL,
tsex BIT NOT NULL,
tage INT CHECK(tage>18 AND tage<80)
)
GO
--4.insert data
INSERT INTO Teacher values('张老师',0,25)
INSERT INTO Teacher values('王老师',1,45)
INSERT INTO Teacher values('李老师',0,30)
GO
--5.select data
SELECT * FROM Teacher
GO
--6.select data as other name
SELECT id AS '编号',tname AS '称谓',tsex AS '性别',tage AS '年龄' FROM Teacher
GO
--7.select data as other value
SELECT id AS '编号',tname AS '称谓',CASE tsex WHEN 0 THEN '女' ELSE '男' END AS '性别',tage AS '年龄' FROM Teacher

 

 

 

posted @ 2014-07-25 10:38  哈特中尉  阅读(242)  评论(0编辑  收藏  举报