SQL important commands
| 1) | database command | |||||
| s.no. | want to use | command syntax | command means type these in sql | output | 1)||
|---|---|---|---|---|---|---|
| i) | CREATE DATABASE | create database [databasename] ex ; | CREATE DATABASE EMP1; | Query OK, 1 rows affected (0.05 sec) | ||
| ii) | SHOW DATABASE | SHOW [database name]; | SHOW DATABASES; | +--------------------+ | Database | +--------------------+ | information_schema | | emp | | emp1 | | emp3 | | estdatabase | | junkdb | | mysql | | performance_schema | | raj | | students | | test | | testdatabase | | testdb | +--------------------+ 13 rows in set (0.84 sec) | ||
| iii) | USE OR SELECT or Switch to a database | use [db name]; | USE EMP1; | mysql> USE EMP1; Database changed | ||
| iv) | To delete database | drop database [database name]; | drop database emp1; | Query OK, 2 rows affected (0.23 sec) | ||
| v) | Add a new column to database | |||||
| vi) | ||||||
| vi) | ||||||
| 2) | table command | |||||
| s.no. | want to use | command syntax | command means type these in sql | output | ||
| (i) | Create Table or make table in database | CREATE TABLE [table name] (firstname VARCHAR(20)); | CREATE TABLE employee (fname VARCHAR(20),lname VARCHAR(35)); | Query OK, 0 rows affected (0.78 sec) | ||
| ii) | see all the tables in the db database | show tables; | +----------------+ | Tables_in_emp1 | +----------------+ | employee | | employee1 | +----------------+ 2 rows in set (0.02 sec) | |||
| (iii) | Manipulating Tables | totaly remove table from database | DROP TABLE EMPLOYEE; | Query OK, 0 rows affected (0.06 sec) | ||
| iv) | To remove a column from a table | ALTER TABLE EMPLOYEE DROP fname; | Query OK, 0 rows affected (0.33 sec) Records: 0 Duplicates: 0 Warnings: 0 | |||
| 11) | To see tables field formats | describe [table name]; | describe EMPLOYEE; | +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | lname | varchar(35) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 1 row in set (0.03 sec) | ||
| 6) | To delete a table’s contents without removing the table completely | DELETE FROM EMPLOYEE; | ||||
| 7) | one statement to delete the same row from more than one table: | DELETE FROM EMPLOYEE, CONFIDENTIAL WHERE empno='00201'; | ||||
| 8) | To retrieve a complete table | SELECT * FROM EMPLOYEE; | ||||
| 9) | all command insert one time store in a file | source books.sql | ||||
| 10) | To login (from unix shell) use -h only if needed. | # [mysql dir]/bin/mysql -h hostname -u root -p | ||||
| 13) | ||||||
| 14) | ||||||
| 15) | ||||||
| 16) | ||||||
| 17) | ||||||
| 18) | ||||||
| 19) | ||||||
| 2) | ||||||
| 2) | ||||||
| 2) | ||||||
| 2) | ||||||
| 2) | ||||||
| 2) | ||||||
| 2) | ||||||
| 2) | ||||||
| 1) | ||||||
| 1) | ||||||
| 5) | ||||||
| 5) | ||||||
| 5) | ||||||
| 5) | ||||||
| 5) | ||||||
h | Query OK, 0 rows affected (0.05 sec) |
| CREATE DATABASE EMP1 |
dropping, or removing, a table from a database
DROP TABLE EMPLOYEE |
C:\Program Files\Java\jdk1.7.0\jre\lib\ext
No comments:
Post a Comment