1.創建數據庫的語句如下:
Create database databaseName
上述語句創建一個名字叫 databaseName 的數據庫
2.刪除數據庫的語句如下。
Drop database databaseName
上述語句將刪除databaseName 數據庫
3.創建表的格式如下:
Create table tableName
(column1 datatype [column_constraint],
column1 datatype[column_constraint],
...
[Constrain primary key pk_table_name(column_n)]
以SQLServer 數據庫為例,用SQL語句穿件用戶表user,該表有 id,name,password,
email, age, birthday, money 字段,數據庫中的字段的數據類型分類分別是int,
varchar,varchar,varchar,int,datetime,float 型。由於在數據庫SQLServer 中 user
是關鍵字,不允許用戶直接使用,因此在user 的兩邊加上[].
create table [user] (id int,name varchar(50),passworld varchar(50),email varchar(50),age int, birthday datetime);
4.刪除表的語句如下:
drop table tableName;
以下語句用於刪除表user。
drop table [user];
5.插入一條記錄的語句格式如下:
insert into tableName (column1,column2,...) values (value1,value2,...);
向user 表中插入一條記錄。
insert into [user] (name,passworld,email,age,birthday)
values ('Funson','888','Funson@163.com',28,'1988-12-08',66.0);
6.刪除符合條件的一條或者多條記錄:
delete from tableName [where ..];
刪除 user表中id 是1 的記錄
delete from user where id=1;
如果去掉where 子句,將刪除 user 表中所有的記錄。
7.更新一條或者多條記錄
update tableName set columnName = newColumnValue;
以下語句中更新 user 表中 id = 1 的 passworld 字段,字段原來的值是123,更新后為456
update [user] set passworld = '456'