The document provides a comprehensive guide on SQL commands for database management, including creating databases and tables, altering table structures, and executing various select queries. It emphasizes the importance of data types and constraints when modifying tables and inserting data. Additionally, it covers functions for data manipulation and retrieval, ensuring proper syntax and usage of SQL commands.
Download as RTF, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
MySqlCommands
The document provides a comprehensive guide on SQL commands for database management, including creating databases and tables, altering table structures, and executing various select queries. It emphasizes the importance of data types and constraints when modifying tables and inserting data. Additionally, it covers functions for data manipulation and retrieval, ensuring proper syntax and usage of SQL commands.
Show create table tablename;. #to desc a table totally including constraint name Alter table tablename drop foreign key constraintname;
14.drop table table_name;
15.drop database database_name;
16.insert into table_name
values(value1,Null,"tanya",..........); Insert into table_name values(values,values,), (values,values);
While populating records in a table with foreign
key, ensure that records in referenced tables are already populated.
17.insert into table_name(column1,columnz,column3...)
values(value1,valuez,value3...);
18.select from table_name,
19.select attribute1, attribute2.. from table_name where
condition; 20.select old_column_name as new_column_name; (if space in new then put in double quotes)
21.select distinct columname from table_name;
select count(distinct cuid) from orders; to count number of distinct values in attribute cuid
22.select *from table_name where columnname1= and
columname2=;
23 select*from table_name where columname between
and # it includes final and initial values
24.select*from table_name where attribute 1= or
attribute1= or attribute1=
25. select from table_name where attribute1 in (~J);
26.select from table_name where attribute1 not in();
Select attribute1 from table_name where not attribute=""; Select attribute1 from tablename where attribute!="";
27.select*from table_name order by attribute;
28.select *from table_name order by attribute desc;
29.select*from table_name where attribute is null;
30.select *from table_name where attribute is not null;
31.select from table_name where attribute like "k%" and attribute2 not in ("_",)
32.select from table_name where attribute like "%a";
33.select from table_name where attribute like "_anya";
34.select from table_name where attribute like "%d%";
Select from tablename where attribute not like"%t_";
35 update table_name set attribute=,attribute1= where
attribute3 in ("-","6","&");
36.delete from student where attribute=;
37.select power(x,y); #returns x raise to power y
38.select round(n,d); #returns the number n with d
rounded off decimal values # -d will return the number with last d numbers replaced with 0 and last second number rounded off # ex round(4568.5,-1) = 4570 Round(435.678,4)=435.678 no change Select truncate(42572.3763,-3) =42000 no rounding off occurs
27.select mod(a,b); #returns remainder of a divide by b
attribute2 from inventory, #to use an attribute from inventory table(price), gst will not reflect in the original table Or Select rollno, length(name) as name from table_name; 29.alter table table_name add attribute decimal(n,m); #total n digits including m decimals
# For float(M,D), double(M,D) or decimal(M,D), M must
be >= D (column 'final_price') # if a number greater then specified limit is entered it round off to the specified limit in above case
#numeric(a,b) same as decimal(a,b)
###following queries dont make changes to the actual