- 论坛徽章:
- 0
|
花了两天时间搞MySQL,其实不算学习应该是复习了,复习也没复习全部只是大概了而已...
1.先抛开c不谈,单单将MySQL...
几个基本的通用的东东应该知道
show databases;
show tables;
use databasename;
describe tablename;
create table tablename(
id INT(4),
name VARCHAR(10),
birth DATE
);
insert into tablename(id, name, birth) values(xx,xxx,xxxx);
update tablename set name='xxxx';
select * from tablename where name='xxx';
delete from tablename where name='xxxx'
2.可以用电小小的正则
select * from tablename where name like 'ken%'('ken_')
上面的正则就那么两个
select * from tablename where name REGEXP 'ken$'('ken.*')
这个正则就和平时用的差不多了...
3.procedures问题
delimiter //
create procedure my()
begin
declare i INT;
set i=1;
while i
insert into ... values....
set i=i+1;
end while;
end;
//
恢复delimiter
delimiter ;
这里还有个就是连接字符串MySQL用concat而不是SQL那种+
然后call my()就可以了...
4.index就是提高查询速度的
create index indexname on tablename(colname(length))
alter table tablename add index indexname(colaname,...)
单列索引就是where name='xxx'
组合索引就是where name='xxx' and age=....这种
5.最后就是c来干这些事了,首先是环境的搭建,这个我上篇日志里已经写了...这个过程是痛苦的
然后就是任何语言,任何DB都逃不过的事了...
连接数据库,这个各异,不过google是肯定知道的
连上后,并且制定数据库后就可以进行具体的操作了
mysql_query(conn, "call add_user()")就是这个了
你也可以mysql_query(conn, "show tables")
or insert等等其他的...
搞定这些基本上应付一般的笔试面试应该就可以了吧,再加上之前的SQL Server, Sqlite的开发经验就可以开始忽悠了...
今天的test发现,index的强大,还真不知道B-树有这么NB,等下还要等大脑高效率的时候看看数据库索引的实现....头大的东东
ok,数据库复习暂告一段落
#include windows.h>
#include MySQL\mysql.h>
#include stdlib.h>
#include stdio.h>
#include conio.h>
// Entry point...
int main(int nArguments, char *pszArguments[])
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "123456"; /* 此处改成你的密码 */
char *database = "test";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
}
/* send SQL query */
if (mysql_query(conn, "call add_user()")) {
fprintf(stderr, "%s\n", mysql_error(conn));
}
if (mysql_query(conn, "select * from user;")) {
fprintf(stderr, "%s\n", mysql_error(conn));
}
res = mysql_use_result(conn);
printf("query:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
system("PAUSE");
return 0;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76292/showart_2040495.html |
|