Skip to content

Commit 388b947

Browse files
authored
Merge pull request #1 from rahull0328/dev
added schema and new answers
2 parents 03ede78 + 4b9c23f commit 388b947

File tree

2 files changed

+667
-0
lines changed

2 files changed

+667
-0
lines changed

README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,175 @@ NOTE: Logical Data Independence is more difficult to achieve.
294294
<div align="right">
295295
<b><a href="#table-of-contents">↥ back to top</a></b>
296296
</div>
297+
298+
## Q. Why E-R models are used?
299+
300+
E-R model stands for entity-relationship model and it is used to represent a model with their relationships. This is an object oriented approach and it is based on real world that consists of objects which are called entities and relationship between them. Entities are further used inside the database in the form of attributes.
301+
302+
<div align="right">
303+
<b><a href="#table-of-contents">↥ back to top</a></b>
304+
</div>
305+
306+
## Q. What do you understand by cardinality and why it is used?
307+
308+
- Cardinality is important and used to arrange the data inside the database.
309+
- It is related to the design part and need to be properly used in database.
310+
- It is used in E-R diagrams and used to show the relationship between entities/tables.
311+
- It has many forms like the basic is one to one, which associate one entity with another.
312+
- Second is one to many: which relates one entity with many entities in a table.
313+
- Third is many to many M: N that allows many entities to be related to many more.
314+
- Last is many to one that allows the many entities to be associated with one entity.
315+
316+
<div align="right">
317+
<b><a href="#table-of-contents">↥ back to top</a></b>
318+
</div>
319+
320+
## Q. What is DDL, DML and DCL?
321+
322+
SQL commands can be divided in three large subgroups.
323+
324+
1) DDL: The SQL commands which deals with database schemas and information of how the data will be generated in database are classified as Data Definition Language.
325+
-For example: CREATE TABLE or ALTER TABLE belongs to DDL.
326+
327+
2) DML: The SQL commands which deals with data manipulation are classified as Data Manipulation Language.
328+
For example: SELECT, INSERT, etc.
329+
330+
3) DCL: The SQL commands which deal with rights and permission over the database are classified as DCL.
331+
For example: GRANT, REVOKE
332+
333+
## Q. How to prevent from database SQL Injection?
334+
335+
SQL Injection is a code-based vulnerability that allows an attacker to read and access sensitive data from the database. Attackers can bypass security measures of applications and use SQL queries to modify, add, update, or delete records in a database.
336+
337+
**Simple SQL Injection Example:**
338+
339+
```sql
340+
SELECT id FROM users WHERE username='username' AND password='password' OR 1=1'
341+
```
342+
343+
Because of the **OR 1=1** statement, the **WHERE** clause returns the first **id** from the **users** table no matter what the **username** and **password** are. The first user id in a database is very often the administrator. In this way, the attacker not only bypasses authentication but also gains administrator privileges.
344+
345+
**Prevent SQL Injections:**
346+
347+
**1. Continuous Scanning and Penetration Testing:**
348+
349+
The automated web application scanner has been the best choice to point out vulnerabilities within the web applications for quite some time now. Now, with SQL injections getting smarter in exploiting logical flaws, website security professionals should explore manual testing with the help of a security vendor.
350+
351+
They can authenticate user inputs against a set of rules for syntax, type, and length. It helps to audit application vulnerabilities discreetly so that you can patch the code before hackers exploit it to their advantage.
352+
353+
**2. Restrict Privileges:**
354+
355+
It is more of a database management function, but enforcing specific privileges to specific accounts helps prevent blind SQL injection attacks. Begin with no privileges account and move on to "read-only", "edit", "delete" and similar privilege levels.
356+
357+
Minimizing privileges to the application will ensure that the attacker, who gets into the database through the application, cannot make unauthorized use of specific data.
358+
359+
**3. Use Query Parameters:**
360+
361+
Dynamic queries create a lot of troubles for security professionals. They have to deal with variable vulnerabilities in each application, which only gets graver with updates and changes. It is recommended that you prepare parameterized queries.
362+
363+
These queries are simple, easy to write, and only pass when each parameter in SQL code is clearly defined. This way, your info is supplied with weapons to differentiate between code and information inputs.
364+
365+
**4. Instant Protection:**
366+
367+
A majority of organizations fail the problems like outdated code, scarcity of resources to test and make changes, no knowledge of application security, and frequent updates in the application. For these, web application protection is the best solution.
368+
369+
A managed web application firewall can be deployed for immediate mitigation of such attacks. It contains custom policies to block any suspicious input and deny information breach instantly. This way, you do not have to manually look for loopholes and mend problems afterward.
370+
371+
<div align="right">
372+
<b><a href="#table-of-contents">↥ back to top</a></b>
373+
</div>
374+
375+
## Q. What are the non standard string types available in SQL?
376+
377+
Following are Non-Standard string types:
378+
379+
| Name | Max Length |
380+
|----------|------------|
381+
|TINYTEXT |255 bytes |
382+
|TEXT |65,535 bytes|
383+
|MEDIUMTEXT|16 MB |
384+
|LONGTEXT |4GB |
385+
386+
<div align="right">
387+
<b><a href="#table-of-contents">↥ back to top</a></b>
388+
</div>
389+
390+
## # 2. SQL Data Types
391+
392+
<br/>
393+
394+
## Q. What is difference between CHAR and VARCHAR in MySQL?
395+
396+
Both of them are used for string type data. `char` has fixed length and if the inserted data is less than the defined length, required no. of blank spaces are added as padding. `varchar` has variable length and no padding is used to fill up the left out space. So technically, varchar will save space.
397+
398+
## Q. What are the string datatypes in SQL?
399+
400+
A list of data types used in MySQL database. This is based on MySQL 8.0.
401+
402+
|Data Types | Description |
403+
|----------------|---------------------------------------|
404+
|CHAR(Size) |It is used to specify a fixed length string that can contain numbers, letters, and special characters. Its size can be 0 to 255 characters. Default is 1.|
405+
|VARCHAR(Size) |It is used to specify a variable length string that can contain numbers, letters, and special characters. Its size can be from 0 to 65535 characters.|
406+
|BINARY(Size) |It is equal to CHAR() but stores binary byte strings. Its size parameter specifies the column length in the bytes. Default is 1.|
407+
|VARBINARY(Size) |It is equal to VARCHAR() but stores binary byte strings. Its size parameter specifies the maximum column length in bytes.|
408+
|TEXT(Size) |It holds a string that can contain a maximum length of 255 characters.|
409+
|TINYTEXT |It holds a string with a maximum length of 255 characters.|
410+
|MEDIUMTEXT |It holds a string with a maximum length of 16,777,215.|
411+
|LONGTEXT |It holds a string with a maximum length of 4,294,967,295 characters.
412+
|ENUM(val1, val2, val3,...)|It is used when a string object having only one value, chosen from a list of possible values. It contains 65535 values in an ENUM list. If you insert a value that is not in the list, a blank value will be inserted.|
413+
|SET( val1,val2,val3,....)|It is used to specify a string that can have 0 or more values, chosen from a list of possible values. You can list up to 64 values at one time in a SET list.|
414+
|BLOB(size) |It is used for BLOBs (Binary Large Objects). It can hold up to 65,535 bytes.|
415+
416+
<div align="right">
417+
<b><a href="#table-of-contents">↥ back to top</a></b>
418+
</div>
419+
420+
## Q. What are the differences between the BLOB and TEXT datatypes in MySQL?
421+
422+
BLOB stands for Binary Large Objects and as its name suggests, it can be used for storing binary data while TEXT is used for storing large number of strings. BLOB can be used to store **binary data** that means we can store pictures, videos, sounds and programs also.
423+
424+
BLOB values behave like byte string and BLOB does not have a character set. Therefore, comparison and sorting is fully dependent upon numeric values of bytes.
425+
426+
TEXT values behave like non-binary string or character string. TEXT has a character set and the comparison/ sorting fully depends upon the collection of character set.
427+
428+
**Creating a table with TEXT data type:**
429+
430+
```sql
431+
mysql> create table TextTableDemo ( Address TEXT );
432+
433+
mysql> DESC TextTableDemo;
434+
```
435+
436+
**Creating a table with BLOB type:**
437+
438+
```sql
439+
mysql> create table BlobTableDemo ( Images BLOB );
440+
441+
mysql> desc BlobTableDemo;
442+
```
443+
444+
<div align="right">
445+
<b><a href="#table-of-contents">↥ back to top</a></b>
446+
</div>
447+
448+
## # 3. SQL Database
449+
450+
<br/>
451+
452+
#### Q. How to create a database using SQL?
453+
454+
To create a database using SQL, you can use the `CREATE DATABASE` statement followed by the name of the database you want to create. Here's the basic syntax:
455+
456+
```sql
457+
CREATE DATABASE database_name;
458+
```
459+
For example, if you want to create a database called "mydatabase", you can run the following SQL query:
460+
461+
```sql
462+
CREATE DATABASE mydatabase;
463+
```
464+
Note that depending on your SQL environment, you may need to have appropriate permissions to create a database.
465+
466+
## # 4. SQL Table
467+
468+
<br/>

0 commit comments

Comments
 (0)