0% 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.

Uploaded by

tarush.jarvis.pa
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% 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.

Uploaded by

tarush.jarvis.pa
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

dont forget to use double quotes in string and date

2. dont forget to use datatype while using alter in some


like modify to get default value or modify not null.

—————————————————————————
——————————————————————

1.create database database_name;

2.use database_name;

3.create table table_name(

attribute1 datatype,

carid varchar(5) primary key);

4.show tables;

5.desc table_name;

6.alter table table_name add columnname datatype;

7.alter table table_name add unique(columnname);


Allows null values but not repetitive values

8.alter table table_name add primary key(columnname);


alter table table_name add foreign key(attribute _name)
references table_name(attribute_name);

9.alter table table_name modify columname datatype;


10.alter table table_name modify columname datatype
not Null;

11.alter table table_name modify columname datatype


default default_value;

12.alter table table_name drop attribute,

13.alter table table_name drop primary key;


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

28.select round(12*price/100,1) "gst", attribute1,


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


table

30.select round(n,o); # round off to integer

31.select ucase(string)[or upper(string)],#uppercase

32.select Icase(string)[or lower(string)]; #lowercase

33.select mid(string,pos, n) [or subst

You might also like