选择语句:select * from [table];
limit语法:
select * from [table] limit 5;//选择前5条记录
select * from [table] limit 5 , 10; //选择第5行到第10行的记录
插入语句:insert into [table] ( column1, column2 , .....) values( value1, vlaue2 , ....);
更新语句:update [table] set [cloumn1]='' , [column2]='' , ..... where [column]='' and .....;
删除语句:delete [table] where column='' and ....;
创建表语句:
MYSQL中的自增列,用AUTO_INCREMENT关键字表示,同时,自增列一定要声明为主键,否则错误。
另外,主键的声明可以在某列之后直接声明,也可以另起一行声明.
设置日期字段的默认值: MySql中规定默认值只能是常量,不能是函数或表达式等。当可以
把字段设置成为TIMESTAMP类型来实现,但TIMESTAMP的范围是1970-2037.
create table [tableName ]
(
[columnkey] int(10) not null auto_increment,
[columnName1] varchar(45) default null ,
[columnName2] varchar(100) default null,
[columnName3] TIMESTAMP(14) default current_timestamp,
[........],
foreign Key( [foreignColumn1] ) references by [tableName].[column] ,
primary key( columnkey );
);
创建数据库语句:
creata database [databaseName];
创建视图语句:
create view [viewName] as select [table1].column1 as column1 , [table2].column1 as column2 ,....... from [table1] join [table2]
where [table1].[column] = [table2].[column] and ......;
创建存储过程语句:
创建存储过程语句,括号是必须的,存储过程的参数必须写在括号里。语句块的开始和结束处要分别用BEGIN和END,当然还要记住最基本的分号。
另外,存储过程的调用语句要用CALL。
如果有输出参数,则OUT关键字一定要在参数名前。
create procedure [sp_Name] ( [in/out ] parameter1 [type] )
begin
select * from [tablename] where [column = parameter1] and .......;
end
调用存储过程:call [sp_name]( [parameter1], ...... );
创建函数语句:
create function [fu_name]( parameter1 [type] ) return [type]
as
begin
declara age int;
select [tableName].[age] into age from [tableName] where [tableName].[column1] = [parameter1];
return age;
end
调用函数语句:select [fu_name]( [paramenter1] , ..... );
MySQL中的数据类型之于SQL Server中的数据类型
解决方法:
SQL Server |
Mysql |
int |
int(11) |
char |
char |
bigint |
bigint(20) |
binary |
binary |
bit |
bit(1) |
datetime |
datetime |
decimal |
decimal |
float |
double |
image |
mediumblob |
money |
decimal(19,4) |
nchar |
char |
ntext |
mediumtext |
numeric |
decimal |
nvarchar |
varchar |
real |
float |
smalldatetime |
datetime |
smallint |
smallint(6) |
smallmoney |
decimal(10,4) |
sql_variant |
mediumblob |
text |
mediumtext |
timestamp |
binary(8) |
tinyint |
tinyint(3) |
uniqueidentifier |
mediumblob |
varbinary |
tinyblob |
varchar |
varchar |