SQL_study_notes1:the_creation_of_database_and_table

0 as a fresh man, there might exist some faults about my codes undoubtly, but everytime when I notice, I would revise to the correct answers as soon as possible.
1 create & use databases

### e.g.
create database xs_test;
use xs_test; 

So the database xs_test has been created, and the follwing table, which would be created, would be put into this database. Now I start to create table.

2 create a table which including some variables

###e.g.
create table xs_table
(
last_name varchar(30),
first_name varchar(20),
email varchar(50),
birthday date,
profession varchar(50),
location varchar(50),
status_ varchar(20),
interests varchar(100),
seeking varchar(100)
); 
### insert some specific values in to this table
insert into xs_table
(
last_name varchar(30) not null,
first_name varchar(20) not null,
email varchar(50) not null,
birthday date,
profession varchar(50),
location varchar(50),
status_ varchar(20),
interests varchar(100),
seeking varchar(100) default null
)
values
(
"leo",
"xu",
"aaaa@bbb.com",
"11/22/1994",
"financial risk analyst",
"Nanchang",
"Jiangxi",
"Movies",
"null"
);
### or just as following, which demand me must put all the values into the table in sequence and without null value.
insert into xs_table values
(
"leo",
"xu",
"aaaa@bbb.com",
"11/22/1994",
"financial risk analyst",
"Nanchang",
"Jiangxi",
"Movies",
"null"
);

Remarks:
1 common data types:
char: it is rigid and prefer its data to be a set length;
int: it should be whole, but it is not afraid of negative numbers;
blob: it likes large gobs of text data;
date: keep track of the dates;
time: keep track of the time;
datetime/timestamp: its expression depend on SQL RDBMS and keep track of the date and time, datetime is best used to store a future event, and timestamp is usually used to capture the current time;
dec: it gives all the decimal places you ask for, until it is full. e.g. dec(5,2);
varchar: it holds text data of up to 255 character in length and it is flexible and can adapt to the length of the data;
2 describing table is to show the details of table.

###e.g.
desc xs_table;

3 drop the existing table;

drop table xs_table;

4 the method to make some special marks( ‘’, “”) not be interpreted by SQL.
we can put a backslash in front of the single quote or just an extre single quote in front of it.
e.g.
’ aa’ bb, cc’
or
’ aa’ ’ bb, cc’

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值