MySQL using essays

Source: Internet
Author: User
Tags mysql delete mysql insert mysql query sprintf

Modify the structure within a table

Modify the column name and type command: ALTER TABLE tbuserinfo Change permissions (callout, this entry is the old field name) permissions (callout, this entry is the new field name) char (2);


The red callout 1 is the command, the Red Callout 2 is the result; for field deletion: 1, view table Tbuserinfo structure 2, delete the field Description command: ALTER table Tbuserinfo DROP Description;





MySQL DELETE statement: Delete from table name where condition; For example, delete from Tbuserinfo where id= 2;MySQL Query statement: SELECT * Column name from table name where condition; mysql fuzzy query: SELECT * FROM table name WHERE column name like "3%"; (indicates that all data with the first character of 3 in the column is queried)MySQL Modify statement: Update table name set column name = ' value ' where condition;MySQL INSERT statement: INSERT into table name values ' content ', ' content ';Linux C data insertion routines (self-write)
1MYSQL *Conn;2 time_t tm_val;3 structTM *GMT;4 Charsql[1024x768];5  6conn=Db_connect ();7Tm_val =Time (NULL);8GMT = LocalTime (&tm_val);9memset (SQL,0,1024x768);Tensprintf (SQL,"INSERT into Tbuserinfo (useraccount,pwd,permissions,createdatetime) VALUES ('%s ', '%s ', '%s ', '%d-%d-%d%d:%d:%d ') ", OneUsername,pwd,quanxian,gmt->tm_year +1900, Gmt->tm_mon +1, Gmt->tm_mday, Gmt->tm_hour, Gmt->tm_min, gmt->tm_sec); A  if(mysql_query (conn, sql)! =0) { -Do_log ("Insert failed!\n"); -  return 0; the  } -Db_disconnect (conn);

Linux c query get query content routines (self-write)
voidUser_list_find (Charresp_data[]) {MYSQL*Conn; Mysql_res*Res;intList_value;inttemp;Charsql[1024x768]; Charbuf[ -]; Charbuf1[4096]; Conn=Db_connect ();//mysql_res *rs;Mysql_row ROW; memset (SQL,0,1024x768); memset (BUF,0, -); memset (BUF1,0,4096); if(get_manager_quanxian[0] =='1') sprintf (SQL,"SELECT * from tbuserinfo WHERE permissions like \ "1%\""); Else if(get_manager_quanxian[0] =='2') sprintf (SQL,"SELECT * from tbuserinfo WHERE permissions like \ "2%\""); Else if(get_manager_quanxian[0]=='3') sprintf (SQL,"SELECT * from tbuserinfo WHERE permissions like \ "3%\""); mysql_query (conn, SQL);//Execute Query Statementres = MYSQL_STORE_RESULT (conn);//get query result setList_value=mysql_num_rows (RES);//get the number of rows found  for(temp=0; temp<list_value;temp++) {row=mysql_fetch_row (RES); sprintf (BUF,"%s,%s.", row[1],row[3]);   strcat (BUF1,BUF); } sprintf (Resp_data,"%d.", List_value); strcat (Resp_data, BUF1); Mysql_free_result (RES); //ReleaseDb_disconnect (conn);//Disconnect Connection}  

through the above two routines can be self-pondering update and delete;

MySQL using essays

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.